eBay / nice-modal-react

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

Unnecessary re-render when showing multiple modals..? #116

Closed jackdunncode closed 9 months ago

jackdunncode commented 1 year ago

I have this structure:

-- Parent ---- Modal -------- Child Modal

When I call NiceModal.show() in the Parent, it opens the Modal, without re-rendering the Parent (which is desired!). Then, in the Modal, I have a function to open a Child Modal. However this causes a re-render to the Modal (which is not desired!).

I have realised that useModal hook seems to be the culprit here, by watching the state change of useModal: image

Here is the sequence of events, shown with console.log:

Opening Modal: image

Then opening Child Modal: image

As you can see, opening the Child Modal causes the first Modal to update (from visible: false back to visible: true).

How can I get around this?

supnate commented 1 year ago

Yes, it's a limitation for now, but a bit difficult to enhance: https://github.com/eBay/nice-modal-react/issues/58 . The workaround is use the static method NiceModal.show(MyModal/id, args) for your case.

jackdunncode commented 1 year ago

Yes, it's a limitation for now, but a bit difficult to enhance: #58 . The workaround is use the static method NiceModal.show(MyModal/id, args) for your case.

I already am using the static method, in both Parent and Modal

jackdunncode commented 1 year ago

Yes, it's a limitation for now, but a bit difficult to enhance: #58 . The workaround is use the static method NiceModal.show(MyModal/id, args) for your case.

I already am using the static method, in both Parent and Modal

Destructuring the following minimised the number of useEffects, but re-render was still occurring

const { visible, resolve, remove } = useModal();

supnate commented 9 months ago

Should have been resolved in v1.2.11.