useGlobalKeyDown()
A utility to quickly setup hotkeys and such.
import {useGlobalKeyDown} from '@sanity/ui'
import isHotkey from 'is-hotkey'
import React, {useCallback} from 'react'
const isSaveHotkey = isHotkey('mod+s')
function App () {
const handleGlobalKeyDown = useCallback(
(event: KeyboardEvent) => {
if (isSaveHotkey(event)) {
event.preventDefault()
// Sanity autosaves your work!
}
},
[]
)
useGlobalKeyDown(handleGlobalKeyDown)
return <>...</>
}
(
callback: (event: KeyboardEvent) => void;
) => void