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

How to close modal from within itself #43

Open
tyler-dunkel opened this issue Dec 14, 2020 · 1 comment
Open

How to close modal from within itself #43

tyler-dunkel opened this issue Dec 14, 2020 · 1 comment

Comments

@tyler-dunkel
Copy link

I am not sure if this is an issue per-say but am attempting to use this library to render a modal and have run into a situation where I am not sure on the best solution. I have a modal that contains a cancel and create button. Clicking either of these should close the modal. However, I am not sure on how to best handle this case. The show/hide functions returned from useModal coupled with needed to pass a function into the modal props (to handle closing the modal after creation) creates a circular dependency. The only way I have found to be able to do it is to pass handleClose and handleCreate func props to the modal and set their value equal to the hideModal function. This doesnt feel correct but I cant figure out another way to handle this case. Example below:

const [showWorkspaceModal, hideWorkspaceModal] = useModal(() => ( <CreateWorkspaceDialog open handleClose={hideWorkspaceModal} handleCreate={hideWorkspaceModal} /> ))

@alewis729
Copy link

@tyler-dunkel this should work just fine:

const [showWorkspaceModal, hideWorkspaceModal] = useModal(({ in: open }) => (
    <CreateWorkspaceDialog
      open={open}
      handleClose={hideWorkspaceModal}
      handleCreate={hideWorkspaceModal}
    />
  ));

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

2 participants