React events
From wikinotes
You can subscribe to DOM events with callbacks similarly to javascript.
except that events are in camelcase
and callbacks are defined as methods rather than strings.
React DOM events are abstracted, so they behave the same on all browsers. See SyntheticEvent docs.
See https://reactjs.org/docs/handling-events.html
Documentation
Event Handling Docs https://reactjs.org/docs/handling-events.html SyntheticEvent Docs https://reactjs.org/docs/events.html
Example
A component, whose element subscribes to the DOM event through
onClick
.class HelloWorld extends React.Component { sayHello() { console.log('hello') } render() { return ( <button onClick={() => this.sayHello()}> // anonymous callback variation Say Hello </button> <button onClick{sayHello}> // instance-method callback variation Say Hello </button> ); } }