Event handling in React
React’s event system is another powerful feature shipped with React core APIs. It is called SyntheticEvent
. As React developers, we will come across event handling daily in React application development projects. Handling events shouldn’t be new to you if you are familiar with the basics of JavaScript. You could add an event to HTML DOM using the browser-native approach.
Let’s have a glimpse at this code snippet:
<html><body> <h1>HTML DOM Operations</h1> <p><strong>Click here to see my message.</strong></p> <div id="root"></div> <script> document.addEventListener("click", function(){ document.getElementById("root").innerHTML = "This is a text added to the DOM tree!"; }); </script> </body> </html>
<div id="root"> </div>
indicates the location where the DOM will inject...