react/prefer-read-only-props
eslint-plugin-react
Safe autofix
eslint.config.js
import react from "eslint-plugin-react";
export default [
{
plugins: { react },
rules: {
"react/prefer-read-only-props": "error",
},
},
];type Props = {
name: string,
}
class Hello extends React.Component<Props> {
render () {
return <div>Hello {this.props.name}</div>;
}
}
function Hello(props: {-name: string}) {
return <div>Hello {props.name}</div>;
}
const Hello = (props: {|name: string|}) => (
<div>Hello {props.name}</div>
);type Props = {
name: string;
}
class Hello extends React.Component<Props> {
render () {
return <div>Hello {this.props.name}</div>;
}
}
interface Props {
name: string;
}
class Hello extends React.Component<Props> {
render () {
return <div>Hello {this.props.name}</div>;
}
}type Props = {
+name: string,
}
class Hello extends React.Component<Props> {
render () {
return <div>Hello {this.props.name}</div>;
}
}
function Hello(props: {+name: string}) {
return <div>Hello {props.name}</div>;
}
const Hello = (props: {|+name: string|}) => (
<div>Hello {props.name}</div>
);type Props = {
readonly name: string;
}
class Hello extends React.Component<Props> {
render () {
return <div>Hello {this.props.name}</div>;
}
}
interface Props {
readonly name: string;
}
class Hello extends React.Component<Props> {
render () {
return <div>Hello {this.props.name}</div>;
}
}Examples from the ESLint documentation.
No tracked preset enables this rule, so it has no reach yet.
None of the tracked presets enable this rule. Turn it on with the config below.
react/prefer-read-only-props
eslint-plugin-react
import react from "eslint-plugin-react";
export default [
{
plugins: { react },
rules: {
"react/prefer-read-only-props": "error",
},
},
];Oxlint does not have this rule.
Biome does not have this rule.
Disallow adjacent inline elements not separated by whitespace.
Enforce React components to have a shouldComponentUpdate method