noReactPropAssignments
Summary
Section titled “Summary”- Rule available since:
v2.0.0 - Diagnostic Category:
lint/correctness/noReactPropAssignments - This rule doesn’t have a fix.
- The default severity of this rule is information.
- This rule belongs to the following domains:
- Sources:
- Same as
react-hooks/react-compiler
- Same as
How to configure
Section titled “How to configure”{ "linter": { "rules": { "correctness": { "noReactPropAssignments": "error" } } }}Description
Section titled “Description”Disallow assigning to React component props.
React’s props are assumed to be immutable, and it is considered bad practice to assign to properties of the props object. When using the React Compiler, this is even a hard error.
Examples
Section titled “Examples”Invalid
Section titled “Invalid”function Foo(props) { props.bar = "Hello " + props.bar; return <div>{props.bar}</div>}code-block.jsx:2:2 lint/correctness/noReactPropAssignments ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
ℹ Mutating component props is not allowed.
1 │ function Foo(props) {
> 2 │ props.bar = “Hello ” + props.bar;
│ ^^^^^
3 │
4 │ return <div>{props.bar}</div>
ℹ Consider using a local variable instead.
const Foo = function({bar}) { bar = "Hello " + bar; return <div>{bar}</div> }Related links
Section titled “Related links”Copyright (c) 2023-present Biome Developers and Contributors.