Skip to content

Event bubbling due to nested components - how to stop propagation? #474

Answered by dbismut
rfmiotto asked this question in Q&A
Discussion options

You must be logged in to vote

Before I dive into the specifics of this question, a few things regarding the code you've provided.

  1. you're using createRef and not useRef. createRef creates a new ref on each render, which is certainly not what you want. In my experience, createRef is mainly used when you need to create a list of refs inside useMemo for example.

  2. In most situations, it's simpler to just use the spread API as in const bind = useGesture(...) and <div {...bind()} /> rather than a ref and a target. You might need refs when you need to run event.preventDefault() as it requires to set eventOptions.passive = false which is not supported by React handlers, but in your case that's irrelevant.

  3. You were running c…

Replies: 1 comment 6 replies

Comment options

You must be logged in to vote
6 replies
@dbismut
Comment options

@rfmiotto
Comment options

@rfmiotto
Comment options

@dbismut
Comment options

@rfmiotto
Comment options

Answer selected by rfmiotto
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