You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Bug]: immutability lint page lists push() and sort() mutations that the rule does not report #8758
The immutability page lists three "Invalid" examples. eslint-plugin-react-hooks 7.1.1 reports only the property assignment (user.name = 'Bob'). The items.push(4) and setItems(items.sort()) examples, and the todos.push() example under Troubleshooting, produce no diagnostic.
This is expected behavior per react/react#35157: method calls on state error only when the compiler knows the type, and it does not infer state types. The page presents them as cases the rule catches.
No diagnostic. The same component with user.name = 'Bob'; setUser(user) reports "This value cannot be modified".
Suggested fix: keep the property assignment as the "Invalid" example and move push() and sort() to a note that says the rule cannot detect method-call mutations on state yet (react/react#35157).
Updates the immutability ESLint rule reference page to accurately reflect rule diagnostics: retains verified object property assignments under ### Invalid and moves mutating methods (push(), sort()) into an instructional Note explaining compiler inference boundaries.
Problem
The immutability rule documentation previously presented three examples under ### Invalid:
items.push(4); setItems(items);
user.name = 'Bob'; setUser(user);
setItems(items.sort());
As reported in #8758 and tracked in react/react#35157, eslint-plugin-react-hooks only emits diagnostics on direct property assignments (like user.name = 'Bob'). Calling mutating methods on state variables produces no diagnostic unless the compiler can fully infer the state type. Presenting push() and sort() as cases flagged by the rule misleads developers when their linter produces no error.
Solution
Accurate Diagnostic Examples: Kept direct property assignment under ### Invalid as the verified case flagged by the linter.
Added Explanatory Note: Introduced a dedicated note explaining that while calling mutating methods like items.push(4) or items.sort() will not trigger a linter diagnostic without inferred types, mutating state in-place is still prohibited because identical references prevent re-renders.
Changes
src/content/reference/eslint-plugin-react-hooks/lints/immutability.md: Refined the Invalid section and added the note on method mutations.
Activity
pawannyadav05 commentedon Nov 21, 2026
Fixes #8758
Summary
Updates the
immutabilityESLint rule reference page to accurately reflect rule diagnostics: retains verified object property assignments under### Invalidand moves mutating methods (push(),sort()) into an instructional Note explaining compiler inference boundaries.Problem
The
immutabilityrule documentation previously presented three examples under### Invalid:items.push(4); setItems(items);user.name = 'Bob'; setUser(user);setItems(items.sort());As reported in #8758 and tracked in
react/react#35157,eslint-plugin-react-hooksonly emits diagnostics on direct property assignments (likeuser.name = 'Bob'). Calling mutating methods on state variables produces no diagnostic unless the compiler can fully infer the state type. Presentingpush()andsort()as cases flagged by the rule misleads developers when their linter produces no error.Solution
### Invalidas the verified case flagged by the linter.items.push(4)oritems.sort()will not trigger a linter diagnostic without inferred types, mutating state in-place is still prohibited because identical references prevent re-renders.Changes
src/content/reference/eslint-plugin-react-hooks/lints/immutability.md: Refined the Invalid section and added the note on method mutations.PR opened in #8769.