Languages
[Edit]
EN

React - add onClick to div

3 points
Created by:
Zoya-Gaines
653

In this article, we would like to show you how to handle a mouse click event on div element in React.

Below example uses:

  • React.useState() hook to store color.
  • onClick property to handle the event.

Practical example:

Note: go to this article to see class component version. 

1
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.

ReactJS

React - add onClick to div
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join