Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

IVLIU
Copy link

@IVLIU IVLIU commented Jun 4, 2024

relate issues

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
Copy link
Author

IVLIU commented Jun 4, 2024

@supnate Please review this PR if you have time.

@IVLIU IVLIU changed the title fix: The issue of being unable to close the popup when using nested p… Fix the issue where some dialogs cannot be closed when using nested providers Jun 4, 2024
@HiChen404
Copy link

Great ! solved my problem.

@rm86626
Copy link

rm86626 commented Jun 4, 2024

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

@supnate supnate self-assigned this Jun 7, 2024
@IVLIU
Copy link
Author

IVLIU commented Jun 25, 2024

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
Copy link
Author

IVLIU commented Jun 25, 2024

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
Copy link
Author

IVLIU commented Jun 25, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants