Bubbling and Capturing in React
Both bubbling and capturing are supported by React. The event handlers are triggered by the bubbling phase. Attach a handler to an eventual parent of an element then any event that is triggered on that element will bubble to the parent until it is stopped by stopPropagation. You have to append Capture to the event name to register an event handler for capture phase. Example: You will use onClickCaputure to handle the click event in the event phase instead of using onClick.
Example for Bubbling:
<div onClick={this.handleClick}><button>Click me, and my parent's `onClick` will fire!</button>
</div>
Example of Capturing:
<div onClickCapture={this.handleClickViaCapturing}><button onClick={this.handleClick}>
Click me, and my parent's `onClickCapture` will fire *first*!
</button>
</div>
Comments
0 comments
Please Sign in or Create an account to Post Comments