function Counter() {
const [count, setCount] = React.useState(0);
console.log(`New count: ${count}`)
const decrementCount = () => {
if (count > 0) setCount(count => count - 1);
};
return (
<>
<MinusBtn onClick={decrementCount} />
<div>{count}</div>
<PlusBtn onClick={() => {
setCount(count => count + 1);
}}
/>
</>
);
};
export default Counter;
Note: Code snippets do not include styling details unless they are the focus of the exercise.
Copyright © 2022 Explore React