Closed stephensamra closed 3 years ago
I believe it is because handlers are not remountable/changed when the handlers
object changes, by design. See https://github.com/greena13/react-hotkeys#setting-dynamic-hotkeys-at-runtime.
The reason that it increments correctly is because you're using the function form of setting a React state. If you did increment: () => setValue(value + 1)
, you'd find you'd have the same issue with incrementing as you do with the show
function, since the updated functions are not passed to <Hotkeys>
when changed.
The quickest way to fix this is add the allowChanges
prop.
@Harjot1Singh Adding the allowChanges
prop worked. Thank you!
Given the following...
... no matter how many times
increment
is called,show
always prints0
.You can see the issue happening in this CodeSandbox. If you press the up arrow 5 times and then press enter, the console prints:
I would expect the last line to say
show: 5
.Any help would be appreciated, thank you!