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

Cannot update the onEscKeyDown function. #524

Open
zoolyka opened this issue Dec 10, 2024 · 1 comment
Open

Cannot update the onEscKeyDown function. #524

zoolyka opened this issue Dec 10, 2024 · 1 comment
Labels

Comments

@zoolyka
Copy link

zoolyka commented Dec 10, 2024

Bug report

Describe the bug

The onEscKeyDown function can be only provided once during the first initialization, it cannot be updated later.

To Reproduce

Create a function with useCallback which depends on some state variable.

  const [ confirmationIsOpen, setConfirmationIsOpen ] = useState(true);
  
  const onEscKeyDown = useCallback(() => {
    console.log(confirmationIsOpen);
    if (
      confirmationIsOpen
    ) {
      closeConfirmation();
    } else {
      closeModal();
    }
  }, [ closeModal, closeConfirmation, confirmationIsOpen ]);

  useEffect(() => {
    const timeout = setTimeout(() => setConfirmationIsOpen(false), 1000);
    return(() => clearTimeout(timeout));
  }, [ setConfirmationIsOpen ]);

  return(<Modal ... onEscKeyDown={onEscKeyDown} />);

When the confirmationIsOpen variable is changed it will still log the initial value on ESC key presses.

Expected behavior

The function should be updated.

System information

  • Version of react-responsive-modal: 6.4.2
@zoolyka zoolyka added the bug label Dec 10, 2024
@zoolyka
Copy link
Author

zoolyka commented Dec 10, 2024

P.S.: The closeOnEsc property also cannot be changed once the modal is initialized, it will use the initial setting during its entire lifecycle.

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

No branches or pull requests

1 participant