Skip to content

Pass handlers to withHotKeys #127

@Floriferous

Description

@Floriferous

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions