Skip to content

Cannot update the onEscKeyDown function. #524

Description

@zoolyka

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

Activity

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

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions