Replies: 1 comment
-
The hook takes a type to set the ref element type:
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Following these docs from the react-hotkeys-hook package (https://react-hotkeys-hook.vercel.app/docs/documentation/useHotkeys/scoping-hotkeys), I am trying to scope the registration of some hotkeys to a particular React component. However, the ref object returned by this package's 'useHotkeys' hook causes a TypeScript error when I try to pass it to a via its ref prop. (I can get the hotkeys to work when I don't scope it to a particular component, but this error prevents the code from building.
My hook code:
Excerpt of the React function component:
This produces this build error:
It appears useHotKeys returns a 'MutableRefObject<Element | null>' but for the div element's ref prop, React expects a 'LegacyRef | undefined'.
When I try forcing the type, the code builds but the hotkeys don't work -- code below:
Beta Was this translation helpful? Give feedback.
All reactions