Skip to content

noReactPropAssignments (JavaScript)

Language JavaScript (and super languages)
biome.json
{
"linter": {
"rules": {
"correctness": {
"noReactPropAssignments": "error"
}
}
}
}

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.

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>

ℹ Props are read-only. Changing them can change data that belongs to the parent component, and React does not rerender when a prop is mutated.

ℹ Consider using a local variable instead.

const Foo = function({bar}) {
bar = "Hello " + bar;
return <div>{bar}</div>
}