react/no-array-index-key
eslint-plugin-react
No autofix
eslint.config.js
import react from "eslint-plugin-react";
export default [
{
plugins: { react },
rules: {
"react/no-array-index-key": "error",
},
},
];things.map((thing, index) => (
<Hello key={index} />
));
things.map((thing, index) => (
<Hello key={`hello-${index}`} />
));
things.map((thing, index) => (
React.cloneElement(thing, { key: index })
));
things.map((thing, index) => (
React.cloneElement(thing, { key: `hello-${index}` })
));
things.forEach((thing, index) => {
otherThings.push(<Hello key={index} />);
});
things.filter((thing, index) => {
otherThings.push(<Hello key={index} />);
});
things.some((thing, index) => {
otherThings.push(<Hello key={index} />);
});
things.every((thing, index) => {
otherThings.push(<Hello key={index} />);
});
// …things.map((thing) => (
<Hello key={thing.id} />
));
things.map((thing) => (
<Hello key={`hello-${thing.id}`} />
));
things.map((thing) => (
React.cloneElement(thing, { key: thing.id })
));
things.map((thing) => (
React.cloneElement(thing, { key: `hello-${thing.id}` })
));
things.forEach((thing) => {
otherThings.push(<Hello key={thing.id} />);
});
things.filter((thing) => {
otherThings.push(<Hello key={thing.id} />);
});
things.some((thing) => {
otherThings.push(<Hello key={thing.id} />);
});
things.every((thing) => {
otherThings.push(<Hello key={thing.id} />);
});
// …Examples from the ESLint documentation.
react/no-array-index-key
eslint-plugin-react
import react from "eslint-plugin-react";
export default [
{
plugins: { react },
rules: {
"react/no-array-index-key": "error",
},
},
];react/no-array-index-key
react plugin · perf
{
"plugins": [
"react"
],
"rules": {
"react/no-array-index-key": "error"
}
}suspicious/noArrayIndexKey
suspicious · since 1.0.0
{
"linter": {
"rules": {
"suspicious": {
"noArrayIndexKey": "error"
}
}
}
}Disallow usage of button elements without an explicit type attribute
Disallow usage of dangerous JSX properties
Disallow void DOM elements (e.g. <img />, <br />) from receiving children
Disallow unnecessary fragments
Disallow usage of referential-type variables as default param in functional component
Disallow missing props validation in a React component definition