-
Notifications
You must be signed in to change notification settings - Fork 99
Cannot update the onEscKeyDown function. #524
Copy link
Copy link
Open
Labels
Description
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
Reactions are currently unavailable