React Events
If you have coded even a little bit in JavaScript, you know the importance of events.
Events
Every HTML attribute in React is written in camelCase syntax. Event is also an attribute. Hence, written in camelCase.
As we learned, variables, states, and JavaScript operations are written in curly braces {}
, and the same is true with React event handlers too! Like this: onClick={show}
<button onClick={show}>Show</button>
Arguments in Events
We can't pass arguments just like that; it will give a syntax error. First, we need to put the whole function in an arrow function, like this:
<button onClick={ () => show('true') }>Show</button>
React Event Object
Event handler can be provided to the function like this:
<button onClick={ (event) => show('true', event) }>Show</button>