Skip to content

Set shortcut using a forEach loop? #705

Discussion options

You must be logged in to vote

Solved it using a hack thanks to Reddit:

useHotkeys(quickActions.map((a) => a.shortcut).join(', '), (_, handler) => {
		const item = quickActions.find((action) => action.shortcut === handler.shortcut)
		if (item) {
			router.push(item.url)
		}
	})

Another comment mentioned that it would be a good idea to include an array.

I am using another library called fzf which has a selector method. It allows me to use a selector to perform fuzzy search on any nested key of an object. Maybe something like that would be cool for react-hotkeys-hook.

Here's an idea for solving the above problem using my proposed API:

useHotkeys(quickActions, {
	selector: action => action.shortcut
	callback: item => {
		r…

Replies: 2 comments 5 replies

Comment options

You must be logged in to vote
4 replies
@JohannesKlauss
Comment options

@deadcoder0904
Comment options

@JohannesKlauss
Comment options

@deadcoder0904
Comment options

Answer selected by deadcoder0904
Comment options

You must be logged in to vote
1 reply
@JohannesKlauss
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants