react-modal icon indicating copy to clipboard operation
react-modal copied to clipboard

Using React 16 portals

Open brmenchl opened this issue 9 years ago • 3 comments

React 16 now officially supports portals. Is there any plan to move from a custom implementation?

Portal documentation: https://reactjs.org/docs/portals.html

brmenchl avatar Nov 03 '17 20:11 brmenchl

Do they use a custom implementation? From what the code says(https://github.com/reactjs/react-modal/blob/master/src/components/Modal.js#L11-L14), they look for react 16 and use the portals already. However, I am having an issue testing with that and enzyme; issue here (https://github.com/airbnb/enzyme/issues/1150). I'm wondering if there's a way for us to say we don't want to use portals if we don't want to (or if other libraries are having issues with it)

comfroels avatar Nov 03 '17 20:11 comfroels

@brmenchl react-modal already has support for react 16 on version v3+.

@comfroels I think the best way (or at least for now) is to define an alias on your compiler config to use a dummy proxy component (which just returns the children or a <div>{children}</div>). This way you will "remove" the Modal from your tests.

Ref: Webpack resolve config Ref: Rollup alias plugin

Another way would be to make the modal content a component itself.

Here is an example: https://codesandbox.io/s/lyqov0lowl

diasbruno avatar Nov 04 '17 14:11 diasbruno

I'm close this for clean up. @comfroels Feel free to open a new issue or follow any other previously opened about testing. Thank you!

diasbruno avatar Nov 06 '17 16:11 diasbruno