A child component keeps showing old data after its prop changed
The parent state changes in the console but the child still shows the first valueShort answer
A child shows stale data when something in it froze the prop's value. useState(prop) reads the prop once, and the parent can mutate an array or object so React sees the same reference and skips the render. Use the prop directly, reset the child with a key, and update parent state with new copies.
Fix it fast
1Find out which cause you have
Log the prop in the child's render body. If it prints the new value while the screen shows the old one, the child copied it into state. If it prints the old value, the parent never produced a new one.
function Child({ item }) { console.log("Child render, prop:", item); // ... }2Match what you see, then jump to its fix
- 1
The prop in the console is new, the screen is old, and the child has useState(props.something)The child copied the prop into useStateFix - 2
The parent used push, sort, or assignment on an array or object in state, and the child shows the old listThe parent mutates state, so the prop keeps the same referenceFix - 3
The child has useEffect(() => setValue(prop), [prop]) and the screen lags one render behindAn Effect copies the prop into stateFix
- 1
What does the error look like?
The parent state changes in the console but the child still shows the first valueThe child updates only after a full page reload
Cause 1 of 3
The child copied the prop into useState
1Check
The argument to useState is the initial value only. React ignores it on every later render, so a later prop change never reaches that state.
grep -rn "useState(props\.\|useState(item\|useState(user" src2Fix
If the child does not edit the value, delete the state and read the prop. If it does edit it, reset the child by giving it a key that changes with the data.
// read the prop directly
function Child({ item }) {
return <h2>{item.name}</h2>;
}
// or reset an editable child when the id changes
<Profile userId={userId} key={userId} />3Verify
Switch to a different item. The child shows its data straight away.
npm run devConfirmed by react.dev
Cause 2 of 3
The parent mutates state, so the prop keeps the same reference
1Check
React treats state as read-only. Calling push on an array in state changes it in place; the setter then receives the same array and the update is not seen as a change.
grep -rn "\.push(\|\.splice(\|\.sort(" src --include=*.jsx --include=*.tsx2Fix
Create a new array or object each time. Use spread to add, map to change one item and filter to remove.
setArtists([...artists, { id: nextId++, name }]);
setArtists(artists.map(a => a.id === id ? { ...a, name: "New name" } : a));
setArtists(artists.filter(a => a.id !== id));3Verify
Click the control that changes the list; the child re-renders with the new list.
npm run devConfirmed by react.dev
Cause 3 of 3
An Effect copies the prop into state
1Check
Copying a prop into state inside an Effect is one of the cases the React docs say does not need an Effect. The state only catches up after an extra render.
grep -rn -B1 -A3 "useEffect" src/components/Child.jsx2Fix
Compute the value while rendering, or reset all state with a key when the prop is an identity such as an id.
function Child({ items, selectedId }) {
const selection = items.find(i => i.id === selectedId);
return <p>{selection?.name}</p>;
}3Verify
Change the prop and watch the screen: it updates in the same render.
npm run devConfirmed by react.dev
How do I stop it coming back?
- Treat props as the source of truth. Add state in the child only for data the child itself edits.
- Never call push, splice, sort or reverse on an array that lives in state; copy it first.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
- TaxiDexMy own multi-tenant taxi dispatch SaaS: API, dispatcher portal, driver and passenger apps, and the servers underneath.
- QistLockA NestJS and React SaaS driving an Android Device Owner agent that locks financed phones when payments lapse.
- TaskvareA task and project-management suite: React on the web, Flutter on mobile, TypeScript underneath.
Related fixes
Web apps
React state still shows the old value right after setState
three setCount(count + 1) calls raise the counter by 1, not 3
A setter does not change the variable in the code that is running.
2 causes, each with a fixWeb apps
Module not found for antd/dist/antd.less after upgrading to Ant Design 5
Module not found: Error: Can't resolve 'antd/dist/antd.less'
Ant Design 5 dropped Less and the bundled CSS file for CSS-in-JS, so antd/dist/antd.less no longer exists.
3 causes, each with a fixWeb apps
Astro Code component fails inside a React component
Astro components cannot be rendered directly via function call
Astro components such as Code only exist on the server and render static HTML.
2 causes, each with a fixWeb apps
React shows Attempted import error when importing a component or function
Attempted import error:
The build found the file but not the name you asked for.
2 causes, each with a fixWeb apps
How to catch and handle a 422 from Axios in a Redux thunk
action.error.message is 'Rejected' and action.payload is undefined
A 422 means the server read the request but cannot process its content, so repeating it unchanged fails again.
4 causes, each with a fixWeb apps
axios gets 429 Too Many Requests from a React app
429 (Too Many Requests)
A 429 comes from the server or an API gateway, not from axios: your client sent too many requests in a window.
4 causes, each with a fix