commit
4047a7ec23
378 changed files with 29334 additions and 0 deletions
19
hooks/useEscapeKey.js
Normal file
19
hooks/useEscapeKey.js
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
import { useEffect, useCallback } from 'react';
|
||||
|
||||
export default function useEscapeKey(handler) {
|
||||
const escFunction = useCallback(event => {
|
||||
if (event.keyCode === 27) {
|
||||
handler(event);
|
||||
}
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
document.addEventListener('keydown', escFunction, false);
|
||||
|
||||
return () => {
|
||||
document.removeEventListener('keydown', escFunction, false);
|
||||
};
|
||||
}, [escFunction]);
|
||||
|
||||
return null;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue