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

Practice




  1. In HTML the event name must be in lowercase :
< button  onclick = ' activLasers () ' >

whereas React follows the CamelCase convention :

< button  onClick = { activLasers } >
  1. In HTML you can return
    false
    to prevent the default behaviour:
< a  href = ' # '  onclick = 'console.log ("The link was clicked.");
return false
; ' />

whereas in React you have to call

preventDefault()
explicitly:
function handleClick(event) {
  event.preventDefault()
  console.log('The link was clicked.')
}
  1. In HTML you need to invoke the function by adding
    ()
    whereas in React you must not add
    ()
    after the function name. (see, for example, the "activLasers" function in the first point)

Comments

To leave a comment

If you have any suggestion, idea, thanks or comment, feel free to write. We really value feedback and are glad to hear your opinion.
To reply

Lectures and tutorial on "Scripting client side JavaScript, jqvery, BackBone"

Terms: Scripting client side JavaScript, jqvery, BackBone