Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

Commit

Permalink
refactor: add ability to preventDefault in useOnKeydown
Browse files Browse the repository at this point in the history
  • Loading branch information
korhaliv committed Nov 14, 2019
1 parent d3a338a commit bb16d7f
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion renderer/hooks/useOnKeydown.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ import { useEffect } from 'react'
*
* @param {string} key Key pressed
* @param {Function} action Action to perform on keydown
* @param {boolean} preventDefault Whether event default should be prevented when hook triggers `action`
*/
export default function useOnKeydown(key, action) {
export default function useOnKeydown(key, action, preventDefault = false) {
const onKeyDown = e => {
if (e.key === key && action) {
preventDefault && e.preventDefault()
action()
}
}
Expand Down

0 comments on commit bb16d7f

Please # to comment.