Listing 3-12: Using an arrow function as an event handler
import {useState} from 'react';
function CountUp(){
const [count,setCount] = useState(0);
return (
<div>
<button onClick={()=>setCount(count+1)}>Add One</button>
{count}
</div>
);
}
export default CountUp;
Download the examples, report issues, and ask/answer questions in the discussion area by visiting the book's github page. All of the code for the book is also available on codesandbox.io for you to play around with.
ReactJS Foundations is published by John Wiley and Sons, Inc and is available in paperback and eBook.