Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass handlers to withHotKeys #127

Closed
Floriferous opened this issue Oct 27, 2018 · 1 comment
Closed

Pass handlers to withHotKeys #127

Floriferous opened this issue Oct 27, 2018 · 1 comment

Comments

@Floriferous
Copy link

I love HOCs, and I believe it would be amazing if picking up this library was as simple as doing this:

const App = props => <MyFullApp />

// Magic, without changing anything but this line in my entire massive code base,
// space bar suddenly triggers something :)
export default withHotKeys({ handlers: { space: () => console.log('it works!') }, global: true })(App);

Or even pass it as the second argument, in the componentProps of the HOC, but that does not seem to work (Am I doing something wrong?).

To be honest, I think that the API of the HOC is bad, since both arguments are passed down to <HotKeys />, in my opinion, it should simply be withHotKeys( componentProps: Object ) to which you can pass all the props you want, including handlers. Sadly, this would be a breaking change, but I believe simpler, and better design.

Also, global would be a shortcut for focused: true, attach: window, which I had to dig for in the issues to find out.

@greena13
Copy link
Owner

greena13 commented Jan 10, 2019

Thanks for your feedback, Floriferous.

The new withHotKeys HoC API in v2.0.0-pre1 looks a lot more like you described. It will be released soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants