Documentation
Rules
no-implicit-key

no-implicit-key (Deprecated)

Rule category

Suspicious.

What it does

Prevents key prop from not being explicitly specified (e.g. spreading key prop from objects).

Why is this bad?

This makes it hard to see if the key was passed correctly to the element or where it came from.

And it’s also be proposed to be deprecated is this RFC: Deprecate spreading key from objects

Examples

This rule aims to prevent spreading key from objects.

Failing

import React from "react";
 
interface ExampleProps {
  items: { id: string; name: string }[];
}
 
function Example({ items }: ExampleProps) {
  return (
    <ul>
      {items.map((item) => (
        <li {...{ key: item.id }}>{item.name}</li>
        //  ^^^^^^^^^^^^^^^^^^^^^
        //  - Prefer specifying key explicitly instead of spreading it from object.
      ))}
    </ul>
  );
}

Passing

import React from "react";
 
interface ExampleProps {
  items: { id: string; name: string }[];
}
 
function Example({ items }: ExampleProps) {
  return (
    <ul>
      {items.map((item) => (
        <li key={item.id}>{item.name}</li>
      ))}
    </ul>
  );
}