Concept: useState and event handling
Create a Counter component that:
import { useState } from 'react';
export default function Counter() {
// Create state here
// Create handler function here
return (
<div>
{/* Display count */}
{/* Add button */}
</div>
);
}
import { useState } from 'react';
export default function Counter() {
const [count, setCount] = useState(0);
function handleClick() {
setCount(count + 1);
}
return (
<div>
<p>Count: {count}</p>
<button onClick={handleClick}>Click me!</button>
</div>
);
}
useState(0) creates state with initial value 0const [count, setCount] - count is current value, setCount updates itonClick={handleClick} passes the function (no parentheses!)