react/prefer-destructuring-assignment
Rule category
Style.
What it does
Enforces the use of destructuring assignment over property assignment.
Examples
This rule aims to enforce the use of destructuring assignment over property assignment.
Failing
function Component(props) {
const items = props.items;
return <div>{items}</div>;
}
function Component(props) {
return <div>{props.items}</div>;
}
function Component(props) {
const { items } = props;
return <div>{items}</div>;
}
Passing
function Component(props) {
const { items } = props;
return <div>{items}</div>;
}
function Component({ items }) {
return <div>{items}</div>;
}
function Component({ items }: { items: string[] }) {
return <div>{items}</div>;
}
function Component({ items, ...rest }) {
return <div {...rest}>{items}</div>;
}