eBay / nice-modal-react

A modal state manager for React.
https://ebay.github.io/nice-modal-react
MIT License
2.04k stars 118 forks source link

Modal not opening when showing by id #8

Closed MarksCode closed 2 years ago

MarksCode commented 2 years ago

I'm wrapping my app in the NiceModal.Provider, registering a modal like this: <ModalDef id="modal_id" component={Modal} />, then trying to open the modal I have registered using NiceModal.show("modal_id"), but nothing happens. I've reproduced this issue here:

https://codesandbox.io/s/nice-modal-example-015ov?file=/src/GlobalModalProvider.tsx:192-236

How come this is not working?

supnate commented 2 years ago

You need to use NiceModal.create to create a HOC of your dialog. https://codesandbox.io/s/nice-modal-example-forked-95dy2?file=/src/Modal.tsx