react-key-handler icon indicating copy to clipboard operation
react-key-handler copied to clipboard

Fires multiple times for multiple instances

Open matthew-dean opened this issue 7 years ago • 4 comments
trafficstars

I have a component that contains this:

<KeyHandler
     keyEventName={KEYPRESS}
     keyValue='Enter'
     onKeyHandle={onKeyHandler}
/>

So, when i make multiple instances of my React component that contains this, I'm finding that onKeyHandler fires for ALL when ONE of them receives a keypress event. Any idea why this is happening or how to prevent it?

matthew-dean avatar Feb 19 '18 20:02 matthew-dean

Firing the key handler for each component is the expected behaviour, if this is unwanted you should move the KeyHandler up one (or more) level(s) and pass the necessary props to your child components.

ayrton avatar Aug 22 '18 03:08 ayrton

I've just noticed that I sometimes get a double fire when there is a prop change due to the update, solved this through a setTimeout

gforge avatar Sep 07 '18 21:09 gforge

@ayrton Is there any chance to add option to disable this? Moving the KeyHandler is not possible for me.

vkolova avatar Sep 14 '18 10:09 vkolova

@gforge that seems a separate issue, could you create a separate issue? @vkolova I am not sure I understand how/why can you explain please

ayrton avatar Sep 16 '18 17:09 ayrton