TanStack / TanStack/hotkeys

feat: allow `enabled` to accept a callback for lazy evaluation

Open Beginner friendly
#105 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
719
Forks
47
Avg merge
5d 5h
Merged PRs (30d)
1

Description

Feature Request

Summary

Currently, the enabled option in HotkeyOptions only accepts a boolean. It would be useful to also accept a callback (i.e. () => boolean) to support lazy evaluation.

Motivation

There are cases where the enabled state depends on values that are re-evaluated at hotkey trigger time, not at registration time. Having to re-register the hotkey every time that condition changes is cumbersome.

A callback form would allow users to defer the check to when the hotkey is actually fired:

useHotkeys('mod+s', save, {
  enabled: () => !isReadOnly,
})
Proposed API change
// Current
enabled?: boolean

// Proposed
enabled?: boolean | (() => boolean)

The implementation would just call enabled() instead of reading it directly when it's a function.

Alternatives considered

Passing a reactive enabled value that changes over time works, but requires the caller to manage that reactivity and causes unnecessary re-registrations.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the HotkeyOptions definition for the enabled option and trace where enabled is checked when a hotkey fires. Update the type and runtime handling so boolean and callback forms are supported, then verify that the callback is evaluated at trigger time and that existing boolean behavior remains unchanged.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
frontend
Issue type
Feature
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
70/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.