react-hooks-js/immutability
Validates against mutating props, state, and other values that [are immutable](https://react.dev/reference/rules/components-and-hooks-must-be-pure#props-and-state-are-immutable)
- Status
- Active
- Category
- React Compiler
- Assessment
- Evidence-required risk
- Required evidence
- source code
- Default severity
- error
Show technical metadata
- Scope
- All supported frameworks
- Active when
- eslint-plugin-react-hooks v6+ installed AND React Compiler detected in project
- Priority
- 73 (P1)
- Source
- eslint-plugin-react-hooks
- Rule set
- oxlint-plugin-react-doctor 0.9.3 (prompt schema 2)
- Documentation
- Official documentation
Validation prompt
Confirm the detector match and collect the required evidence before deciding whether an edit is warranted.
Fires on writes to values the compiler proves are immutable: props, useState values, useReducer state: via property assignment (state.x = v), in-place array methods (push, pop, splice, sort, reverse), or Object.assign(state, ...).
Suppress when: the value is an Immer produce() draft (draft.x = v is legal inside the producer) or some other proxy that intentionally exposes mutable semantics.
Evidence boundary
The diagnostic proves only that the detector’s modeled source pattern matched. It does not prove runtime impact, product intent, rendered failure, or that one remediation is correct.
Establish the environment, repository policy, exceptions, and required rendered or runtime evidence before deciding the occurrence.
Record one outcome:
- Confirmed failure: The required evidence establishes the violation.
- Rejected: A documented exception or false-positive predicate applies.
- Needs evidence: Named evidence can still be collected.
- Unavailable: Required evidence cannot be collected in this run.
- Waived with evidence: An authorized, scoped exception applies to an established failure.
- Observation: The review records an optional tradeoff without claiming a defect.
A waiver records its scope, authority, evidence, and review condition. It is not a pass or false positive.
Default severity is registry metadata. Use the occurrence’s JSON severity after repository configuration when ordering real findings.
Fix prompt
Apply this candidate correction only after the required evidence confirms the risk.
Always create a new container: setItems([...items, newItem]) or setUser({ ...user, name }): spread at every nested level you change. For deep updates prefer useReducer with explicit immutable cases, or wrap producer code in Immer's produce(). React relies on reference identity (Object.is) to detect changes, so mutating the same array/object silently skips re-renders. See https://react.dev/reference/eslint-plugin-react-hooks/lints/immutability
Repository-wide copy prompt
Use this repository-wide prompt only after validating each occurrence. For one occurrence, use the guidance above.
Show repository-wide prompt
Fix every confirmed react-hooks-js/immutability diagnostic in the current repository.
Required change:
- Always create a new container: setItems([...items, newItem]) or setUser({ ...user, name }): spread at every nested level you change. For deep updates prefer useReducer with explicit immutable cases, or wrap producer code in Immer's produce(). React relies on reference identity (Object.is) to detect changes, so mutating the same array/object silently skips re-renders. See https://react.dev/reference/eslint-plugin-react-hooks/lints/immutability
Validation before editing:
Fires on writes to values the compiler proves are immutable: props, useState values, useReducer state: via property assignment (state.x = v), in-place array methods (push, pop, splice, sort, reverse), or Object.assign(state, ...).
Suppress when: the value is an Immer produce() draft (draft.x = v is legal inside the producer) or some other proxy that intentionally exposes mutable semantics.
Constraints:
- Confirm every occurrence independently.
- Make the smallest change that addresses the root cause.
- Preserve unrelated behavior, interfaces, content, and semantics.
- Reuse existing project conventions and components.
- Do not suppress the rule merely to clear the report.
Assessment:
- Record detector evidence, applicability, missing evidence, and one outcome: Confirmed failure, Rejected, Needs evidence, Unavailable, Waived with evidence, or Observation.
Verification:
- Run focused tests and every repository-mandated check.
- Run React Doctor and confirm the diagnostic no longer appears from changed code.
- Run an unfiltered scan of the affected scope before claiming no cross-category regression.
- Report checks that were not run instead of claiming they passed.