react/destructuring-assignment
eslint-plugin-react
Safe autofix
eslint.config.js
import react from "eslint-plugin-react";
export default [
{
plugins: { react },
rules: {
"react/destructuring-assignment": "error",
},
},
];Enforce consistent usage of destructuring assignment of props, state, and context
const MyComponent = (props) => {
return (<div id={props.id} />)
};const Foo = class extends React.PureComponent {
render() {
return <div>{this.context.foo}</div>;
}
};const MyComponent = ({id}) => {
return (<div id={id} />)
};const MyComponent = ({id}) => {
return (<div id={id} />)
};const MyComponent = (props, context) => {
const { id } = props;
return (<div id={id} />)
};const Foo = class extends React.PureComponent {
render() {
const { title } = this.context;
return <div>{title}</div>;
}
};Examples from the ESLint documentation.
react/destructuring-assignment
eslint-plugin-react
import react from "eslint-plugin-react";
export default [
{
plugins: { react },
rules: {
"react/destructuring-assignment": "error",
},
},
];Oxlint does not have this rule.
Biome does not have this rule.
Enforce all defaultProps have a corresponding non-required PropType
Enforce closing bracket location in JSX
Enforce class component state initialization style
Enforce closing tag location for multiline JSX
Disallow usage of setState in componentWillUpdate