eBay / nice-modal-react

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

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

Closed ArturKustyaev closed 1 year ago

ArturKustyaev commented 1 year ago

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 commented 1 year ago

i have the same problem, any idea resolved it?

supnate commented 1 year ago

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 commented 1 year ago

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

duccadhv1 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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

ArturKustyaev commented 1 year ago

Thanks for the reply, i appreciate it ❤