UNPKG

@tanstack/react-hotkeys

Version:

React adapter for TanStack Hotkeys

26 lines (24 loc) • 728 B
import { getHotkeyManager } from "@tanstack/hotkeys"; import { useSelector } from "@tanstack/react-store"; //#region src/useHotkeyScopesState.ts /** * React hook that returns the hotkey manager's scope state: the active * scopes, the exclusive scope that owns the keyboard, and the scopes it * allows or suspends. Re-renders when scopes activate or release. * * @returns The current scope state * * @example * ```tsx * function KeyboardOwner() { * const { exclusive } = useHotkeyScopesState() * * return exclusive ? <p>Shortcuts belong to {exclusive}</p> : null * } * ``` */ function useHotkeyScopesState() { return useSelector(getHotkeyManager().scopes, (state) => state); } //#endregion export { useHotkeyScopesState };