Understanding Props in React (Beyond âRead-Onlyâ)
Props in React are often described as âread-only,â but that can be misleading at first. This post breaks down what props actually are, why modifying them seems to work, and the key difference between mutation and derivation.
When learning React, one of the first things you hear is:
âProps are read-only.â
That sounds simple â but it can be misleading.
Because at some point, youâll probably write something like this:
function Child({ value }) {
value = value + 1
return <h1>{value}</h1>
}And then youâll wonder:
âWait⌠didnât React say props are read-only? Why does this still work?â
This is exactly where confusion starts.
What Props Actually Are
At a high level:
- Props are data passed from parent â child
- They are treated as immutable inputs
But hereâs the important part:
Props are not special objects â they are just function arguments.
What This Syntax Really Means
This line:
function Child({ value }) {Looks like something special.
But itâs actually just JavaScript destructuring.
Equivalent to:
function Child(props) {
const value = props.value
}So What Happens When You âModifyâ It?
Letâs look again:
function Child({ value }) {
value = value + 1
return <h1>{value}</h1>
}What youâre really doing is:
let value = props.value
value = value + 1So:
- You are NOT modifying the original prop
- You are only modifying a local variable
What Gets Rendered
function App() {
return <Child value={10} />
}Inside Child:
value = 10
value = value + 1 â 11So the result is:
<h1>11</h1>Why This Is Still Considered Wrong
Even though it âworks,â it creates the wrong mental model.
It makes it look like:
âI can change props inside a componentâ
But thatâs not whatâs happening.
You are not mutating props â you are shadowing them with a local variable.
This distinction is subtle, but important.
Mutation vs Derivation
The correct way to think about props is:
Donât mutate â derive
Instead of:
value = value + 1Do this:
const newValue = value + 1Now itâs clear:
valuestays untouchednewValueis computed
Why React Calls Props âRead-Onlyâ
React doesnât enforce immutability at the JavaScript level.
But conceptually:
Props should never be treated as something you can change.
Because:
- They belong to the parent
- The child should only use, not control them
The Real Mental Model
A better way to think about props:
Props = inputs to a functionAnd like any good function:
- You donât modify inputs
- You compute outputs from them
Where Confusion Usually Comes From
If youâve used Vue before, this might feel strange.
In Vue:
- Props are strictly enforced as immutable
- You use
emitto communicate upward
In React:
- Props are just arguments
- You pass callbacks instead of emitting events
At first, React can feel more âmanual.â
But itâs also more explicit.
Why This Design Exists
React prefers:
Explicit data flow over hidden behaviorSo instead of:
- Hidden event systems
- Implicit communication
You get:
- Clear data passing (props)
- Clear actions (callbacks)
Final Takeaway
The most important realization is this:
Props are not something you change â they are something you derive from.
And more importantly:
âRead-onlyâ in React is about mindset, not enforcement.