-
Hi there, I am working on a project in which I am facing a problem with event bubbling. I have 2 nested components, each containing their own gesture handlers and I am trying to cancel the event coming from the parent component when the user clicks and drags the inner component. Minimal project reproducing the issueTo better understand the problem I'm facing, I create a minimal NextJS project on StackBlitz. Related materialI looked at a few Q&A on the web related to this issue (like here, here, here and here for example), but I still couldn't figure it out how to cancel propagation from the parent. When used along with react-spring, it is possible to pass an According to Mozilla and to react-gesture docs, we could cancel events coming from a parent listener by using the event options (capturing). Maybe I didn't understand it correctly, because my attempts didn't work. Thanks in advance for any help you can offer. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 6 replies
-
Before I dive into the specifics of this question, a few things regarding the code you've provided.
Now regarding your issue.
Working sandbox: https://stackblitz.com/edit/nextjs-wzecdq?file=pages%2Findex.js |
Beta Was this translation helpful? Give feedback.
Before I dive into the specifics of this question, a few things regarding the code you've provided.
you're using
createRef
and notuseRef
.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 insideuseMemo
for example.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 runevent.preventDefault()
as it requires to seteventOptions.passive = false
which is not supported by React handlers, but in your case that's irrelevant.You were running
c…