State is Local to Each Component Instance
What you'll learn: Why creating two <Counter /> components gives you two independent counters, not one shared count.
The Core Idea
When you call useState inside a component, React creates that state for that specific instance of the component. If you render the same component multiple times, each copy gets its own separate state that doesn't affect the others.
Think of it like this: if you buy two calculators, pressing buttons on one doesn't change the display on the other. Each calculator maintains its own numbers independently. Components with state work the same way.
How It Works in Practice
function Counter() {
const [count, setCount] = useState(0);
return (
<button onClick={() => setCount(count + 1)}>
Clicked {count} times
</button>
);
}
function App() {
return (
<div>
<Counter />
<Counter />
<Counter />
</div>
);
}
Here you've rendered three <Counter /> instances. Each one has its own count state starting at 0. Clicking the first button only updates the first counter's state. The other two counters remain at 0 until you click their buttons.
React tracks which state belongs to which component instance by their position in the component tree. The first <Counter /> gets the first state slot, the second gets the second slot, and so on.
Why This Matters
This independence is fundamental to React's component model. It means components are truly reusable — you can drop the same component anywhere without worrying about instances interfering with each other.
Key Takeaway: Each component instance maintains its own independent state; rendering the same component multiple times creates multiple separate states, not one shared state.