0
What is the difference between HTML and React event handling?

Open 1 Answers 31 Views Education
What is the difference between HTML and React event handling?

1 Answer

0

Below are some of the main differences between HTML and React event handling,

  1. In HTML, the event name usually represents in lowercase as a convention:

    <button onclick='activateLasers()'>

    Whereas in React it follows camelCase convention:

    <button onClick={activateLasers}>
  2. In HTML, you can return false to prevent default behavior:

    <a ****='#' onclick='console.log("The link was clicked."); return false;' />

    Whereas in React you must call preventDefault() explicitly:

    function handleClick(event) {
      event.preventDefault()
      console.log('The link was clicked.')
    }
  3. In HTML, you need to invoke the function by appending () Whereas in react you should not append () with the function name. (refer "activateLasers" function in the first point for example)

by (280k points)
...