Skip to content

require-react-component-keys

Requires keys for JSX used as list output.

The rule looks for JSX returned from iteration callbacks such as .map(...) and from memoization callbacks such as useMemo(...). In those contexts, JSX elements need a key, and JSX fragments need to be replaced with a keyed element.

It skips ordinary top-level component returns, JSX passed through most props, ternary children, logical child fragments, and a small ignore list of call expressions. By default it also reports a key on a plain root component return, because that key is usually ignored by the parent.

Incorrect
function UserList({ users }) {
return users.map((user) => <UserCard user={user} />);
}
Correct
function UserList({ users }) {
return users.map((user) => <UserCard key={user.id} user={user} />);
}
OptionTypeDefault
allowRootKeysbooleanfalse
ignoreCallExpressionsstring[]["ReactTree.mount", "CreateReactStory"]
iterationMethodsstring[]["map", "filter", "forEach", "flatMap", "reduce", "reduceRight", "some", "every", "find", "findIndex"]
memoizationHooksstring[]["useCallback", "useMemo"]