useKeyHold | useHeldKeys should also return a ref
Open
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 719
- Forks
- 47
- Avg merge
- 5d 5h
- Merged PRs (30d)
- 1
Description
TanStack Hotkeys version
v0.9.1
Framework/Library version
React v18.3.1
Describe the bug and the steps to reproduce it
there are cases when when you don't want to introduce a useCallback dependency
const isCtrlKeyDown = useKeyHold('Control');
const onWheel = useCallback((event: MouseEvent) => {
// if (isCtrlKeyDown) <- needs a callback dependency
// if (isCtrlKeyDownRef.current) <- no dependency
}, []);
current implementation assumes you always rely on state
Your Minimal, Reproducible Example - (Sandbox Highly Recommended)
Screenshots or Videos (Optional)
No response
Do you intend to try to help solve this bug with your own PR?
Yes, I think I know how to fix it and will discuss it in the comments of this issue
Terms & Code of Conduct
- I agree to follow this project's Code of Conduct
- I understand that if my bug cannot be reliable reproduced in a debuggable environment, it will probably not be fixed and this issue may even be closed.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading the useKeyHold and useHeldKeys implementations referenced in the issue, then trace how their current state value is produced. Done means callers can access a ref current value for use in callbacks without adding the state value as a dependency, while preserving the existing state usage.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- react, typescript
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 55/100