Skip to content

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

Closed

Description

@ArturKustyaev

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

Activity

  1. duccadhv1 commented on Feb 15, 2023

    @duccadhv1

    i have the same problem, any idea resolved it?

  2. supnate commented on Feb 15, 2023

    @supnate
    Collaborator

    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} />
        </>
      );
    }
  3. duccadhv1 commented on Feb 15, 2023

    @duccadhv1

    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?

  4. supnate commented on Feb 15, 2023

    @supnate
    Collaborator

    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.

  5. supnate commented on Feb 15, 2023

    @supnate
    Collaborator

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

  6. ArturKustyaev commented on Feb 20, 2023

    @ArturKustyaev
    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions