Event Handling

Events in HTML are also used in React. The only difference is their naming is different in React. Events in React are written in camelcase. Say – onclick becomes onClick.

  • Consider the following code in HTML:
<button onclick="activate()"> activate </button>

Translates to:

<button onClick={activate}> activate </button>

In class-based components, we can directly add arrow functions in the callback. In class-based components, the function has been used in combination with this. For eg: this.activate

  • Read more about event handling here.