In React js to every drag event there is a corresponding event with "capture" prefix onDragEnter vs onDragEnterCapture, onDragLeave vs onDragLeaveCapture and so on. Could any one tell difference between those and when to use which? They both repond to similar events.
Basically Bubbling and Capturing are two ways of event propagation.
Bubbling :
When an event happens on an element, it first runs the handlers on it, then on its parent, then all the way up on other ancestors.
Let’s say we have 3 nested elements form> div> p with a handler on each of them:
A click on the inner <p> first runs onclick:
<p>.<div>. <form>.Capturing : The event is first captured by the outermost element and propagated to the inner elements:
So in the same example when you click the outer element <form> it runs on :
<form><div><p>While using react, to register an event handler for the capture phase, append Capture to the event name; for example, instead of using onClick, you would use onClickCapture to handle the click event in the capture phase.
The same goes for the other events.
Source [1] [2]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With