Overview
- Create local state
- A counter needs a place to remember its number. useState gives us that memory.const [count, setCount] = useState(0);
- A counter needs a place to remember its number. useState gives us that memory.
- Show the state
- Whatever is in
count
should be visible in the UI.<h1 data-testid="count-value">{count}</h1>
- Whatever is in
- Wire up the “+” button
- Clicking + should add 1.<button data-testid="increment-btn" onClick={() => setCount(c => c + 1)} > + </button>
- Clicking + should add 1.
- Wire up the “–” button
- Clicking – should subtract 1. <button data-testid="decrement-btn" onClick={() => setCount(c => c - 1)} > – </button>
- Clicking – should subtract 1.
import Counter from "./Counter"; export default function App() { return ( <div className="min-h-screen bg-gray-50 p-4 flex justify-center"> <Counter /> </div> ); }
JavaScript Console
console.log()statements will appear here
Tests