Each Component Instance Has Its Own State
What you'll learn: How React keeps state completely separate when you render the same component multiple times.
When you use the same component more than once in your app, each instance maintains its own independent state. Think of it like having two identical calculators on your desk—pressing buttons on one doesn't affect the numbers on the other.
The Core Idea
Every time you write <Counter /> in your JSX, React creates a new, separate "state container" for that component. If you render <Counter /> three times, you get three independent counters, each with its own state value and setter function.
function Counter() {
const [count, setCount] = useState(0);
return (
<button onClick={() => setCount(count + 1)}>
Clicks: {count}
</button>
);
}
function App() {
return (
<div>
<Counter /> {/* Has its own count */}
<Counter /> {/* Has its own count */}
<Counter /> {/* Has its own count */}
</div>
);
}
Clicking the first button only updates the first counter's state. The other two remain at zero. Each Counter instance is completely isolated.
Why This Matters
This isolation is fundamental to React's component model. It means you can reuse components fearlessly—they won't interfere with each other. The state lives "inside" each instance, not globally or in the component definition itself.
Key Takeaway: State is isolated per component instance—rendering the same component multiple times creates completely independent state values that don't affect each other.