What is the difference between HTML and React event handling?

Technology CommunityCategory: ReactWhat is the difference between HTML and React event handling?
VietMX Staff asked 3 years ago

Below are the few differences between HTML and React event handling, 1. In HTML, the event name should be in lowercase.

<button onclick="activateLasers()">

Whereas in ReactJS it follows camelCase convention,

<button onClick={activateLasers}>
  1. In HTML, you can return false to prevent default behavior,
<a href="#" onclick="console.log('The link was clicked.'); return false"/>
  1. Whereas in ReactJS you must call preventDefault explicitly,
function handleClick(e) {
      e.preventDefault();
      console.log('The link was clicked.');
}