콘텐츠로 이동

noReactPropAssignments

이 콘텐츠는 아직 번역되지 않았습니다.

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>

Consider using a local variable instead.

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