What is onClickCapture Event in ReactJS?
Last Updated :
19 Mar, 2025
The onClickCapture event in React is part of React’s event handling system, and it is used to handle click events during the capture phase of event propagation. It is a variant of the standard onClick event, but it differs when it is triggered in the event lifecycle.
In the event propagation model, events can propagate in two phases
- Capture Phase: The event starts from the root and propagates down to the target element.
- Bubbling Phase: The event starts from the target element and propagates up to the root.
Syntax
<button onClickCapture = {function}/>
- element: The JSX element that will trigger the event (e.g., <button>, <div>, etc.).
- onClickCapture: The event handler for the capture phase of the click event.
- handlerFunction: The function that will be called when the event is triggered during the capture phase.
By default, React’s onClick event is handled during the bubbling phase, which means the event is fired when it reaches the target element. However, onClickCapture allows you to handle the event during the capture phase, meaning it is triggered before the event reaches the target element.
Using onClickCapture in React
To use onClickCapture, simply attach it to a React element as you would with onClick.
JavaScript
//App.js
import React from "react";
function App() {
const onClickCaptureHandler = () => {
console.log("onClickCapture!");
};
return (
<div className="App">
<h1> Hey Geek!</h1>
<label>Please click on the button</label>
<button onClickCapture={onClickCaptureHandler}>
click Me!
</button>
</div>
);
}
export default App;
Output

In this example
- It uses onClickCapture on the button to demonstrate event capturing.
- Renders a button, label, and header within the App component.
- Exports App as the default component.
When Should You Use onClickCapture?
The onClickCapture event is useful when you need to intercept events before they reach their target element. Some common scenarios where it might be helpful include:
- Logging: You can use onClickCapture to log event details before any other handler processes the event.
- Validation: If you need to validate or check conditions before allowing an event to continue, onClickCapture allows you to stop event propagation early.
- Intercepting events: Intercept events for tasks like analytics or tracking clicks without interfering with the standard flow of the event.
Preventing Default Behavior Using onClickCapture
Just like onClick, you can use event.preventDefault() and event.stopPropagation() in the onClickCapture event handler to stop the event from propagating further.
JavaScript
import React from "react";
class PreventDefaultComponent extends React.Component {
handleClickCapture = (event) => {
event.preventDefault();
event.stopPropagation();
console.log("Default behavior prevented during the capture phase");
};
handleClick = () => {
console.log("Event triggered during the bubble phase");
};
render() {
return (
<div onClickCapture={this.handleClickCapture} style={{ padding: "20px" }}>
<form onSubmit={(e) => e.preventDefault()}>
<button
type="submit"
onClick={this.handleClick}
style={{ padding: "10px", backgroundColor: "lightblue" }}
>
Submit
</button>
</form>
</div>
);
}
}
export default PreventDefaultComponent;
Output
Preventing Default BehaviorIn this example
- onClickCapture handles events during the capture phase (before they reach the target element).
- handleClickCapture prevents the default behavior (form submission) and stops propagation using event.preventDefault() and event.stopPropagation().
- handleClick is triggered in the bubble phase, but the event doesn't reach it because of the capture phase interception.
- The button click does not submit the form, and the message "Default behavior prevented during the capture phase" is logged.
onClickCapture and Event Propagation
Event propagation in the DOM consists of two phases: the capture phase and the bubble phase. By default, events bubble up from the target element, but with onClickCapture, you can intervene during the capture phase, before the event reaches the target.
Breakdown of Event Propagation with onClickCapture:
- Click Event is Triggered: The user clicks on an element (e.g., a button).
- Capture Phase Starts: The event travels down from the root element to the target element (the button).
- onClickCapture Fires: If there is an onClickCapture handler on any parent element, it fires during the capture phase.
- Bubble Phase Starts: After the event reaches the target, the bubble phase starts, and the event bubbles up.
- onClick Fires: The onClick handler on the target element is triggered during the bubble phase.
JavaScript
import React from "react";
class EventPropagation extends React.Component {
handleCapture = (event) => {
console.log("Captured at parent during the capture phase");
};
handleParentClick = (event) => {
console.log("Clicked on parent (Bubble phase)");
};
handleChildClick = (event) => {
console.log("Clicked on child (Bubble phase)");
};
render() {
return (
<div
onClickCapture={this.handleCapture}
onClick={this.handleParentClick}
style={{ padding: "20px", border: "1px solid black" }}
>
<div
onClick={this.handleChildClick}
style={{ padding: "10px", backgroundColor: "lightblue" }}
>
Click Me (Child)
</div>
</div>
);
}
}
export default EventPropagation;
Output
onClickCapture and Event Propagation
In this code
- handleCapture: This function is triggered during the capture phase on the parent div (using onClickCapture). It fires before the event reaches the target (child element).
- handleParentClick: This function handles the event during the bubble phase on the parent div (using onClick). It fires after the event reaches the target and bubbles back up to the parent.
- handleChildClick: This function is triggered during the bubble phase on the child div (using onClick). It fires after the event reaches the child element and begins bubbling up to the parent.
Difference Between onClick and onClickCapture
Feature | onclick (Bubble Phase) | onClickCapture (Capture Phase) |
---|
Trigger Timing | Fires after the event reaches the target and starts bubbling up. | Fires before the event reaches the target while traveling down. |
Propagation Phase | Bubble phase | Capture phase |
Common Use Cases | Regular event handling | Intercepting, validation, or logging |
Conclusion
The onClickCapture event in React is a powerful feature that allows you to handle click events during the capture phase of event propagation. It is useful for intercepting and managing events before they reach their target elements. This event is often combined with onClick to handle events both in the capture phase and the bubbling phase.
Similar Reads
JavaScript Tutorial JavaScript is a programming language used to create dynamic content for websites. It is a lightweight, cross-platform, and single-threaded programming language. It's an interpreted language that executes code line by line, providing more flexibility.JavaScript on Client Side: On the client side, Jav
11 min read
Web Development Web development is the process of creating, building, and maintaining websites and web applications. It involves everything from web design to programming and database management. Web development is generally divided into three core areas: Frontend Development, Backend Development, and Full Stack De
5 min read
React Interview Questions and Answers React is an efficient, flexible, and open-source JavaScript library that allows developers to create simple, fast, and scalable web applications. Jordan Walke, a software engineer who was working for Facebook, created React. Developers with a JavaScript background can easily develop web applications
15+ min read
React Tutorial React is a powerful JavaScript library for building fast, scalable front-end applications. Created by Facebook, it's known for its component-based structure, single-page applications (SPAs), and virtual DOM,enabling efficient UI updates and a seamless user experience.Note: The latest stable version
7 min read
JavaScript Interview Questions and Answers JavaScript is the most used programming language for developing websites, web servers, mobile applications, and many other platforms. In Both Front-end and Back-end Interviews, JavaScript was asked, and its difficulty depends upon the on your profile and company. Here, we compiled 70+ JS Interview q
15+ min read
Domain Name System (DNS) DNS is a hierarchical and distributed naming system that translates domain names into IP addresses. When you type a domain name like www.geeksforgeeks.org into your browser, DNS ensures that the request reaches the correct server by resolving the domain to its corresponding IP address.Without DNS, w
8 min read
HTML Interview Questions and Answers HTML (HyperText Markup Language) is the foundational language for creating web pages and web applications. Whether you're a fresher or an experienced professional, preparing for an HTML interview requires a solid understanding of both basic and advanced concepts. Below is a curated list of 50+ HTML
14 min read
NodeJS Interview Questions and Answers NodeJS is one of the most popular runtime environments, known for its efficiency, scalability, and ability to handle asynchronous operations. It is built on Chromeâs V8 JavaScript engine for executing JavaScript code outside of a browser. It is extensively used by top companies such as LinkedIn, Net
15+ min read
What is an API (Application Programming Interface) In the tech world, APIs (Application Programming Interfaces) are crucial. If you're interested in becoming a web developer or want to understand how websites work, you'll need to familiarize yourself with APIs. Let's break down the concept of an API in simple terms.What is an API?An API is a set of
10 min read
Top 10 Projects For Beginners To Practice HTML and CSS Skills Learning to code is an exciting journey, especially when stepping into the world of programming with HTML and CSSâthe foundation of every website you see today. For most beginners, these two building blocks are the perfect starting point to explore the creative side of web development, designing vis
8 min read