use-focus-return automatically returns focus to the last focused element when a given condition is met.
For example, it is used in Modal component to restore focus after the modal was closed.
Close the modal with the
Escape key and see how focus returns to the button after the modal closes:
In most cases, you should use this hook with use-focus-trap.
shouldReturnFocus option is set to
false you can call returned function to focus last active element: