How to add event handler to React.DOM element dynamically?

Posted by Andre Scott | Updated on

Want to add event handler to React.DOM element dynamically? You don’t want to mess with click handlers on each button, just listen for the click on the container. Then update the state based on which child is clicked.

Also, with React it’s best to keep all of your DOM stuff in the render function. In this case, defining an element’s class name.

Here is an example:


If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.

Related Questions & Answers