useKeyPress Custom Hook
Keypress events are triggered whenever a user hits any of the keys on the keyboard and some action happens on the web application. Create a custom hook called useKeyPress to listen for Key press events. Once a specific key combination is hit, show a toast or a modal on the screen.
Tasks
- Create a custom hook
useKeyPress
that takes in one value - the key
that you want to listen to.
- The syntax will look like this
const shiftKey = useKeyPress('Shift');
// Here, the user listens for the shiftKey press.
- Create a combination of
Shift
and Enter
keys that, when presssed together, should open a toast
on the screen indicating that the combination has been successfully hit.
- For toasts, use the library
react-hot-toast
which is already imported in the project.