How to use Events in ReactJS ?

devquora
devquora

Posted On: Feb 22, 2018

 

Using Events is React js is very similar to handling event on DOM elements.The difference is only in syntax like.
  1. The name of event is React js is always in camelCase.
  2. With JSX you pass a function as the event handler, rather than a string.

Lets understand by an example:

// In HTML
<button onclick="activateAccount()">
  Activate Account
</button>
//In React
<button onClick={activateAccount}>
  Activate Account
</button>

Another difference is that in React js you cannot return false to prevent default behavior in React. You must call preventDefault explicitly. Read more from https://facebook.github.io/react/docs/handling-events.html

    Related Questions

    Please Login or Register to leave a response.

    Related Questions

    React Js Interview Questions

    What is ReactJS ?

    React js is javascript based UI Library developed at Facebook, to create an interactive, stateful &amp; reusable UI com..

    React Js Interview Questions

    List some advantages of ReactJS ?

    Advantages of React JsReact.js is extremely efficient: React.js creates its own virtual DOM where your components act..

    React Js Interview Questions

    What are Components in ReactJS ?

    React Components let you split the UI into independent, reusable pieces, and think about each piece in isolation.Concep..