Common Props and State Mistakes That Cause React Bugs
Props and state mistakes cause most beginner React bugs. Here are the common ones and how to avoid them.
Common Props and State Mistakes That Cause React Bugs
Most beginner React bugs come from a small set of props and state mistakes. Here are the common ones and how to avoid each.
Mutating State Directly
Changing a state variable directly instead of using the setter means React does not detect the change, and the UI does not update. Always use the setter function.
Mutating Objects and Arrays in State
Even with the setter, mutating the same object in place can fail to trigger a re-render because React compares references. Replace objects and arrays with new copies instead.
Copying Props Into State
Duplicating a prop into state creates two sources of truth that drift apart. Keep one source of truth: let the parent own the value.
Calling the Setter During Render
Calling a state setter in the render body causes an infinite re-render loop. Only update state in handlers, effects, or callbacks.
Storing Derived Values in State
If a value can be computed from props or other state, do not store it. Computing it during render avoids sync bugs.
Forgetting the key Prop in Lists
When mapping data to elements, missing keys or using the array index causes subtle bugs when the list changes.
Passing New References Every Render
Creating new objects or functions inline and passing them as props causes unnecessary child re-renders. This matters for performance-sensitive components.
The Takeaway
Most React bugs trace to: mutating state, duplicating data, updating during render, or storing derived values. Avoid these and a large share of beginner bugs disappear.
Usually because you mutated the state variable directly instead of using the setter, or mutated an object in place so React did not detect a reference change. Always use the setter and replace objects and arrays with new copies.
Because it creates two sources of truth that can drift apart. When the prop changes, the copied state does not update, causing bugs. Keep one source of truth and let the parent own the value.
You are calling a state setter directly in the render body. Only update state inside event handlers, effects, or callbacks. Calling the setter during render triggers a re-render that calls it again, creating a loop.
No. If a value can be computed from props or existing state, compute it during render. Storing derived values creates synchronization bugs when the underlying source changes.
Usually because of missing or wrong keys. Every item rendered from a list needs a stable, unique key. Using the array index causes bugs when items are added, removed, or reordered.
Ready to master React completely?
Want to upskill yourself, crack your next interview, and get your dream job? Join our comprehensive course to dive deeper with high-quality video tutorials, solve interview questions, and a premium community.
Master React
Want to upskill yourself, crack your next interview, and get your dream job? Join our comprehensive course.

