Sub topic 5
Editing Values Live to Reproduce Bugs
This chapter assumes you can write function components, use useState and props, and open the Components tab of React Developer Tools. You should already know how to select a component and read its props, state, and hooks. Here you will change those values from the panel and watch the app respond.
Why edit values instead of code
Many bugs only show up in a specific state. A list with zero items, a user with a very long name, a request that failed, or a counter at its maximum are all examples. Reaching these states through the UI can take many clicks, or may need a server to misbehave.
The Components tab lets you write new values directly into a selected component. React re-renders that component with the new value. You do not edit source files, restart the dev server, or lose the rest of your page state. This makes edits useful for three jobs:
- Reproducing a bug that depends on an unusual value.
- Testing a hypothesis about which value causes the bug.
- Checking a fix idea before you write any code.
What can be edited
When you select a component, the right-hand pane shows sections for props, hooks, and sometimes state. Which values are editable depends on the type.
| Value | Editable | Notes |
|---|---|---|
| Strings, numbers, booleans | Yes | Click the value, type, press Enter. |
| `null` and `undefined` | Replace with another value | Type a new value over it. |
| Plain objects and arrays | Yes, per entry | Expand, then edit individual fields. |
| Functions | No | They display as `ƒ` and cannot be replaced. |
| Props on a component | Yes, for function and class components | The change lasts until the parent re-renders and passes the prop again. |
| `useState` and `useReducer` hooks | Yes | The change is real state and persists. |
| `useRef`, `useMemo`, `useCallback` | Mostly read-only | You see the value but cannot usefully replace it. |
| Context values | Read-only in the component | Change the provider's own state instead. |
The row about props matters most for understanding what you see, so the next section covers it.
Editing state versus editing props
State belongs to the component. When you edit a useState hook, DevTools calls the same kind of update that the setter would. The new value is real, and later renders build on it.
Props belong to the parent. When you edit a prop, DevTools overrides the value for that component. The component re-renders with your value. But the parent still holds its own idea of the prop. The next time the parent re-renders, it passes the original value again, and your edit is lost.
This is a common source of confusion. If your edited prop "snaps back", the parent re-rendered. It is not a DevTools fault. To make a prop change stick, select the parent and edit the state that produces the prop.
A worked example
Consider a small cart summary that formats a total and shows a message for large orders.
import { useState } from 'react';
function CartSummary({ items }) {
const [coupon, setCoupon] = useState('');
const total = items.reduce((sum, item) => sum + item.price * item.qty, 0);
const discount = coupon === 'SAVE10' ? total * 0.1 : 0;
return (
<section>
<h2>Total: ${(total - discount).toFixed(2)}</h2>
<input
value={coupon}
onChange={(e) => setCoupon(e.target.value)}
placeholder="Coupon"
/>
{items.length === 0 && <p>Your cart is empty.</p>}
{total > 1000 && <p>Free shipping applied.</p>}
</section>
);
}
export function App() {
const [items] = useState([
{ id: 1, name: 'Keyboard', price: 49.99, qty: 1 },
{ id: 2, name: 'Mouse', price: 19.5, qty: 2 },
]);
return <CartSummary items={items} />;
}Suppose a user reports that the page shows Total: $NaN sometimes. You suspect a missing price. Reproducing it through the UI is not possible, because the items are hard-coded here, and in a real app they come from an API.
- Open the Components tab and select
CartSummary. - In the props pane, expand
items, then expand the first entry. - Click the value
49.99next topriceand replace it withundefined. If the field rejects that, delete thepriceentry or type"abc". - Press Enter. The heading changes to
Total: $NaN.
You have reproduced the symptom in about ten seconds, and you now know that a bad price value causes it. The fix belongs where the data arrives, or in a guard such as Number(item.price) || 0.
Next, test the empty-cart message. In the same pane, you cannot delete the whole items array by clicking, but you can edit its entries. For a stronger edit, select App, find the useState hook in the hooks pane, and change items to []. Now CartSummary receives an empty array, and the message appears. Because you edited state in the parent, the change persists across re-renders.
Finally, select CartSummary and edit the coupon hook to SAVE10. The input and total update together, since you edited the real state.
Editing the components that use hooks
In the hooks pane, each hook appears in call order, labeled by type (State, Reducer, Ref, Memo, and so on). Custom hooks appear as a group that you can expand to see the primitive hooks inside.
For useState, edit the value directly. For useReducer, the displayed value is the current state, and you can edit it, though no reducer logic runs. The state is replaced as if the reducer had returned it. This bypasses your action handling, so a reducer that normally keeps two fields in sync can end up inconsistent after a manual edit. If something looks impossible after an edit, ask whether your edit created a state the reducer would never produce.
Boolean toggles
Booleans show a checkbox. Clicking it flips the value at once. This is the fastest way to test conditional UI such as modals, loading flags, and error flags. For example, toggling isLoading on a data component lets you inspect the skeleton screen without throttling the network.
Reproducing error and edge states
Edits are most useful for states that are hard to trigger:
- Loading and error flags. Flip
isLoadingorerrorin a hook and check the layout. - Long text. Replace a name with a 200-character string to test wrapping and truncation.
- Empty and single-item lists. Edit the array in state to test the empty state and singular wording such as "1 items".
- Extreme numbers. Set a quantity to
0, a negative value, or1e9. - Missing optional props. Replace an optional object with
nullto see if the component reads a property ofnulland crashes.
If an edit makes the component throw, React shows your error boundary, or unmounts the tree if there is none. Reload the page to recover. That crash is itself useful information: it shows that the component does not defend against that input.
Limits and pitfalls
- Strict types are your job. The editor accepts
"5"as a string. If your code expects a number,"5" * 2still works but"5" + 2gives"52". A type mismatch you create by editing may not be a real bug. Match the type your API would return. - Memoized components. If a component is wrapped in
memo, an edit to its props still causes a render, because DevTools forces the update. Do not conclude that memoization is broken from this. - Derived state in the parent. If a parent computes a prop from its own state, editing the prop is temporary. Edit the source state.
- Effects run. Changing state can trigger
useEffecthooks. An effect that fetches data or writes to storage will run with your fake value. Be careful in an environment connected to real services. - Production builds. Editing is meant for development use. Production builds hide names and may limit what you can inspect, which the build modes chapter covers.
From edit to fix
A good habit follows a short loop:
Repeating the same edit after your fix is the check that matters. Reload first, because your fix only runs in a fresh page, then apply the identical value.
Exercise
You edit a prop on a child component in DevTools and the UI updates. A moment later, after you type in an unrelated input in the parent, the prop returns to its old value. Why, and how do you make the change persist?
Show answer
The parent re-rendered because of its own state change and passed the original prop value again, which overwrote your DevTools override. To make it persist, select the parent component and edit the state (the hook) that produces that prop.
Exercise
A reducer keeps total equal to the sum of items. You edit total to 0 in the hooks pane while items has three entries, and the UI shows odd results. Is this necessarily a bug in your reducer?
Show answer
No. Editing the reducer state replaces it directly without running the reducer, so you created a state the reducer would never produce. Edit through the app's real actions, or change both fields consistently, before drawing conclusions.