src/content/docs/linter/rules/no-react-prop-assignments.mdx
import { Tabs, TabItem } from '@astrojs/starlight/components';
<Tabs> <TabItem label="JSX and TSX" icon="seti:javascript"> ## Summary - Rule available since: `v2.0.0` - Diagnostic Category: [`lint/correctness/noReactPropAssignments`](/reference/diagnostics#diagnostic-category) - This rule isn't recommended, so you need to enable it. - This rule doesn't have a fix. - The default severity of this rule is [**information**](/reference/diagnostics#information). - This rule belongs to the following domains: - [`react`](/linter/domains#react) - Sources: - Same as [`react-hooks/react-compiler`](https://github.com/facebook/react/blob/main/packages/eslint-plugin-react-hooks/README.md){
"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>
}
const Foo = function({bar}) {
bar = "Hello " + bar;
return <div>{bar}</div>
}