Props vs State: Who Owns the Data
What you'll learn: When to use props versus state based on who "owns" and controls each piece of data.
The Ownership Question
Every piece of data in your React app lives somewhere. The key decision is: who controls this data?
- Props are owned by the parent component. The parent decides what value to pass down, and the child just receives and uses it.
- State is owned by the component itself. That component controls the value and can change it whenever needed.
Think of it like a parent-child relationship in real life:
- Props are like instructions from a parent: "Wear this jacket today." The child doesn't get to change what jacket was chosen.
- State is like the child's own belongings: "I'll decide which toy to play with right now."
Making the Right Choice
Ask yourself: "Does this component need to control and change this value?"
- Use props when the parent component should be in charge (display a user's name passed from above)
- Use state when the component itself needs to manage the value (track whether a toggle is on/off)
Data flows down through props, but each component can manage its own state internally.
Why This Matters
Choosing correctly prevents confusion. If you try to change a prop value directly (which React forbids!), you're fighting against the ownership model. If you pass everything as props when some values should be internal state, you're making the parent unnecessarily complex.
Key Takeaway: Props are owned by the parent and passed down; state is owned by the component itself. Choose based on who needs control of the data.