In javascript, we use onclick event and in React we use the onClick event. My question is event provides my React is the same as a javascript event or React handle event differently.
2 Answers
React uses a synthetic event system, which is a cross-browser wrapper around the browser’s native event. In most cases, a developer may not notice the differences, but they do exist:
- React synthetic events work identically across browsers.
- React event handlers cannot return false to prevent the default behavior.
- React synthetic events always bubble.
- Before React 17, React synthetic events cannot be used in an asynchronous way unless e.persist() is called.
- React’s synthetic event system for videos works the same way as HTML/JavaScript Events.
Comments
onclick and onClick events are the same.
The only difference is the capital of the "C".
Warning
onclick event is deprecated in javascript. Now, we use addEventListener and then onclick event inside.
1 Comment
Endless
onclick is not depricated - it's perfectly fine to use it on your own element where only one event listener needs to be registered. if you build some tool/package then you should use addEventListener