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

Fix the issue where some dialogs cannot be closed when using nested providers

Open IVLIU opened this issue 1 year ago • 8 comments

relate issues

  • #100
  • #141

feature

  1. optimize parts of the TypeScript implementation.
  2. the issue of being unable to close the popup when using nested providers.

sample

Please refer to the following example. You can switch the imports to see the effects before and after the fix.

https://codesandbox.io/p/sandbox/nice-modal-sample-l4hj7d?file=%2Fsrc%2FApp.tsx%3A50%2C64

and

I tried to maintain compatibility as much as possible, so I added extra parameters to the show, hide, and remove methods to support dispatch definition.

IVLIU avatar Jun 04 '24 06:06 IVLIU

@supnate Please review this PR if you have time.

IVLIU avatar Jun 04 '24 06:06 IVLIU

Great ! solved my problem.

HiChen404 avatar Jun 04 '24 07:06 HiChen404

谢谢,我在开发中也遇到了同样的问题,已解决

rm86626 avatar Jun 04 '24 14:06 rm86626

Additionally, if you prefer not to use useModal, that's also an option.

import { show, DispatchContext } from '@ebay/nice-modal-react'

const dispatch = useContext(DispatchContext)
show(Dialog, { name: 'hello world' }, dispatch)

or

import { show, reducer, initialState, Provider } from '@ebay/nice-modal-react'
const [modals, dispatch] = useReducer(reducer, initialState)

show(Dialog, { name: 'hello world' }, dispatch)

<Provider modals={modals} dispatch={dispatch}></Provider>

IVLIU avatar Jun 25 '24 10:06 IVLIU

Perhaps we can provide a hook to automatically bind the dispatch.

const { show, hide, remove, Provider } = useProvider()

Of course, the naming still needs consideration.

IVLIU avatar Jun 25 '24 10:06 IVLIU

I kept the deprecated_dispatch approach for progressive enhancement, ensuring that the previous code can still run perfectly. However, I'm not sure if deprecated is the right term.

IVLIU avatar Jun 25 '24 10:06 IVLIU

Any update on this?

svajunas-budrys avatar Sep 23 '25 11:09 svajunas-budrys

Any update on this?

No one handles this

IVLIU avatar Sep 23 '25 12:09 IVLIU