in Education by
What is the difference between HTML and React event handling?

1 Answer

0 votes
by

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 href='#' 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)

Related questions

0 votes
    What is the difference between state and props in React?...
asked Jun 2, 2021 in Education by JackTerrance
0 votes
    How to pass a parameter to an event handler or callback in REACT?...
asked Jun 2, 2021 in Education by JackTerrance
0 votes
    What is the difference between Element and Component?...
asked Jun 2, 2021 in Education by JackTerrance
0 votes
    Why should we not update the state directly in React?...
asked Jun 2, 2021 in Education by JackTerrance
0 votes
    What are props in React?...
asked Jun 2, 2021 in Education by JackTerrance
0 votes
    What is state in React JS?...
asked Jun 2, 2021 in Education by JackTerrance
0 votes
    What are Pure Components in React js1?...
asked Jun 2, 2021 in Education by JackTerrance
0 votes
    How to bind methods or event handlers in JSX callbacks?...
asked Jun 2, 2021 in Education by JackTerrance
0 votes
    What is the purpose of callback function as an argument of setState()?...
asked Jun 2, 2021 in General by JackTerrance
0 votes
    When to use a Class Component over a Function Component?...
asked Jun 2, 2021 in Education by JackTerrance
0 votes
    What is JSX?...
asked Jun 2, 2021 in Education by JackTerrance
0 votes
    I am exploring Float Label pattern for web page using HTML and CSS. The code was referred from http: ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 27, 2022 in Education by JackTerrance
0 votes
    I'm trying to handle Winsock_Connect event (Actually I need it in Excel macro) using the following code: ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 19, 2022 in Education by JackTerrance
0 votes
    I'm trying to handle Winsock_Connect event (Actually I need it in Excel macro) using the following code: ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 19, 2022 in Education by JackTerrance
0 votes
    What is a listener in context to event handling? (a) A listener is a variable that is notified when an ... Event Handling of Java Select the correct answer from above options...
asked Feb 24, 2022 in Education by JackTerrance
...