React State Mutation: Why the Screen Doesn’t Update and How to Fix It
If you call push on a React state array, or assign to a property of a state object, and then pass that same array or object to the set function, the screen does not change. React compares the new value with the current state, and if they are the same, it skips the re-render. If a button does nothing when you add an item to a to-do list or change a profile's age, create a new array or object and pass that instead.
Mutations do not always show up on screen right away, so it also helps to know how to find them. In my test environment, I checked how the count goes wrong in Strict Mode's development build, and how far readonly types and ESLint can catch these mutations.
The test environment was Ubuntu 24.04, Node.js 22.23.4, React 19.3.1, TypeScript 6.0.3, esbuild 0.28.2, Playwright 1.63.0, Chromium 153, ESLint 10.15.0, eslint-plugin-react-hooks 7.1.1, and typescript-eslint 8.72.2. I type-checked the .tsx files with tsc, bundled them with esbuild, loaded them into Chromium with Playwright, pressed the buttons, and recorded the displayed text. I tested both development and production builds. I did not test useReducer, class components, or Immer. I did not investigate why the first press inside Strict Mode added only one cat (React's internal behavior).
Passing the Same Array or Object Makes React Think Nothing Changed
In the following component, pressing "Add" calls push on items and then passes the same items to setItems.
const [items, setItems] = useState<string[]>(['たま']);
const [count, setCount] = useState(0);
// ...
<button
onClick={() => {
items.push('みけ');
setItems(items);
}}
>
追加
</button>
<button onClick={() => setCount(count + 1)}>カウント +1</button>
In my test environment, pressing "Add" twice still showed "Tama (1 cat)". Then I pressed "Count +1", which changes a different state, and the display showed "Tama, Mike, Mike (3 cats)". The same thing happened with an object property assignment. Pressing the button twice with cat.age = cat.age + 1; setCat(cat); still showed "Tama is 3 years old".
React compares the value passed to the set function with the current state using Object.is, and if they are the same, it skips the re-render (see the caveats for the set function in the official reference). Arrays and objects are compared by identity, not by their contents. Since push leaves the array itself unchanged, React ignores the update. The contents do change, however, so the new items appear when some other state update causes a re-render.
Create a New Array or Object and Pass It
To fix this, create a new array or object and pass it, without changing the original.
setItems([...items, 'みけ']);
setCat({ ...cat, age: cat.age + 1 });
With this code, each press changed the display: "Tama, Mike (2 cats)", "Tama, Mike, Mike (3 cats)", and then "Tama is 4 years old" and "Tama is 5 years old". The official documentation says to treat objects and arrays stored in state as read-only (see Updating Objects in State and Updating Arrays in State). The arrays page also has a table of non-mutating alternatives to sort and splice.
Mutating Inside an Updater Function Gives the Wrong Count in Strict Mode
Mutations can also happen inside an updater function. In the following code, prev is pushed onto and then a copy is returned. The screen changes because a new array is returned, but prev itself has been mutated.
setItems((prev) => {
prev.push('みけ');
return [...prev];
});

I pressed "Add" four times, both with the component wrapped in <StrictMode> and without it. The table shows the number of "Mike" entries after each press.
| Presses | Without Strict Mode | Inside Strict Mode (development build) | Inside Strict Mode (production build) |
|---|---|---|---|
| 1st | 1 | 1 | 1 |
| 2nd | 2 | 3 | 2 |
| 3rd | 3 | 5 | 3 |
| 4th | 4 | 7 | 4 |
Only in the development build inside <StrictMode> did the first press add one cat and each press after that add two. In the production build, even inside <StrictMode>, each press added one cat.
Strict Mode calls updater functions twice during development only. One of the two results is discarded, but both push calls act on the same array, so two items are added each time. The official reference also gives, as an example where calling the function twice reveals the mistake, pushing onto a state array inside an updater function. The fix is to leave prev unchanged and return a new array.
setItems((prev) => [...prev, 'みけ']);
If the count is off only during development inside <StrictMode>, check whether you are mutating prev inside an updater function. The production build looks correct, so a mismatch in development is a useful clue.
Using readonly Types Makes tsc Block Mutations
If you make the type argument of useState
readonly string[] or Readonly<Cat>, mutations become type errors.
const [items, setItems] = useState<readonly string[]>(['たま']);
const [cat, setCat] = useState<Readonly<Cat>>({ name: 'たま', age: 3 });
items.push('みけ'); // error
cat.age = cat.age + 1; // error
setItems((prev) => {
prev.push('みけ'); // error
return [...prev];
});
setItems([...items, 'みけ']); // passes
setCat({ ...cat, age: cat.age + 1 }); // passes
When I ran tsc on the test file, the three lines that mutate state produced errors (the line numbers refer to the test file).
ng/readonly.tsx(9,11): error TS2339: Property 'push' does not exist on type 'readonly string[]'.
ng/readonly.tsx(13,9): error TS2540: Cannot assign to 'age' because it is a read-only property.
ng/readonly.tsx(18,12): error TS2339: Property 'push' does not exist on type 'readonly string[]'.
This is because the readonly string[] type has no push method, and properties of Readonly<Cat> cannot be assigned to. The prev passed to the updater function has the same type, so its push also became an error. The code that creates a new array or object passed type checking.
ESLint's immutability Rule Only Caught Property Assignment
eslint-plugin-react-hooks has an immutability rule that detects mutations of state and props. In my test environment, loading only the recommended config (recommended) produced errors from this rule.
// eslint.config.js
import tseslint from 'typescript-eslint';
import reactHooks from 'eslint-plugin-react-hooks';
export default [
{ files: ['src/**/*.tsx', 'lint/**/*.tsx'], languageOptions: { parser: tseslint.parser } },
reactHooks.configs.flat.recommended,
];
When I ran this on a file that collected the components from this article, there was one error. (The output path is replaced with /path/to/app.)
/path/to/app/src/cases.tsx
46:11 error Error: This value cannot be modified
Modifying a value returned from 'useState()', which should not be modified directly. Use the setter function to update instead.
/path/to/app/src/cases.tsx:46:11
44 | <button
45 | onClick={() => {
> 46 | cat.age = cat.age + 1;
| ^^^ `cat` cannot be modified
47 | setCat(cat);
48 | }}
49 | > react-hooks/immutability
✖ 1 problem (1 error, 0 warnings)
Only the property assignment was flagged. items.push('みけ') in the same file and prev.push('みけ') inside the updater function did not produce errors.
The rule's documentation lists items.push(4); setItems(items); as a violation. When I copied that example into a separate file and linted it with eslint-plugin-react-hooks 7.1.1, nothing was reported and the exit code was 0. If you also want to stop push on arrays, combine this with the readonly types from the previous section.





