const Counter() => {
const [count, setCount] = useState(0);
useEffect(() => {
if(count > 10){
setCount(0)
}
});
const handleUpdate = ()=> {
setCount (count + 1)
}
return (
<div>
<div>I can only count to 10</div>
<div>Count: {count}</div>
<button onClick={ handleUpdate} >
Click me
</button>
</div>
);
}
Please Login or Register to comment