![]() |
VOOZH | about |
The onClick event in React is used for handling a function when an element, such as a button, div, or any clickable element, is clicked.
Syntax
onClick={handleClick}Parameter
Return Type
Example 1: In this React code, the button text and heading message toggle on click using state changes.
Output:
Example 2: In this React code, each time the button is clicked, it increments a number by 1 and displays the updated value on the screen.
Output: