JohannesKlauss / react-hotkeys-hook

React hook for using keyboard shortcuts in components.
https://react-hotkeys-hook.vercel.app/
MIT License
2.56k stars 112 forks source link

The useRecordHotkeys hook should allow us to programatically set the keys #1139

Open christianlundberg opened 4 months ago

christianlundberg commented 4 months ago

Is your feature request related to a problem? Please describe. It's currently impossible to update the value of the keys while recording a shortcut.

Describe the solution you'd like The useRecordHotkeys could also return a setKeys function which we could use to programatically change the value of the keys.

const [keys, { setKeys }] = useRecordHotkeys();

const onChangeKeys = () => {
    setKeys(new Set(['ctrl']));
};

Describe alternatives you've considered I've resorted to mutating the Set of keys, which is a bad practice in React.

Additional context Add any other context or screenshots about the feature request here.

JohannesKlauss commented 4 months ago

What is your use case for that functionality?