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

Problem with getting data from react-router-dom useParams hook #104

Closed
ArturKustyaev opened this issue Feb 10, 2023 · 7 comments
Closed

Comments

@ArturKustyaev
Copy link

Can't get data from react-router-dom useParams hook using it inside NiceModal.create() function.

CodeSandbox: https://codesandbox.io/s/nice-modal-useparams-bug-dm3qz8

@duccadhv1
Copy link

i have the same problem, any idea resolved it?

@supnate
Copy link
Collaborator

supnate commented Feb 15, 2023

To use the router params, plz use the declarative way:
https://opensource.ebay.com/nice-modal-react/#declarative

For example:

export default function AntdSample() {
  return (
    <>
      <Button type="primary" onClick={() => NiceModal.show('my-antd-modal', { name: 'Nate' })}>
        Show Modal
      </Button>
      <MyAntdModal id="my-antd-modal" {...otherProps} />
    </>
  );
}

@supnate
Copy link
Collaborator

supnate commented Feb 15, 2023

See the updated codesandbox: https://codesandbox.io/s/nice-modal-useparams-bug-forked-riu9d7

@duccadhv1
Copy link

duccadhv1 commented Feb 15, 2023

See the updated codesandbox: https://codesandbox.io/s/nice-modal-useparams-bug-forked-riu9d7

but in your example i comment this line <Modal id="my-modal"/> and use show() method <Button onClick={() => NiceModal.show(Modal)}>show modal</Button> i have problem, because i used create method for register modal, any way for this?

@supnate
Copy link
Collaborator

supnate commented Feb 15, 2023

See the updated codesandbox: https://codesandbox.io/s/nice-modal-useparams-bug-forked-riu9d7

but in your example i comment this line <Modal id="my-modal"/> and use show() method <Button onClick={() => NiceModal.show(Modal)}>show modal</Button> i have problem, because i used create method for register modal, any way for this?

In case you want your modal to be rendered in the current context, it must be declared as a normal component and manage it by id.

@supnate
Copy link
Collaborator

supnate commented Feb 15, 2023

An alternative way is get params in the component where you call modal.show then pass the parameters to the modal.

@ArturKustyaev
Copy link
Author

Thanks for the reply, i appreciate it ❤

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

No branches or pull requests

3 participants