Skip to content

Latest commit

 

History

History
88 lines (60 loc) · 2.09 KB

File metadata and controls

88 lines (60 loc) · 2.09 KB
title no-implicit-key

Full Name in @eslint-react/eslint-plugin

@eslint-react/no-implicit-key

Full Name in eslint-plugin-react-x

react-x/no-implicit-key

Features

💭 🧪

Presets

recommended-type-checked strict-type-checked

Description

Prevents implicitly passing the 'key' prop to components.

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

It is also proposed to be deprecated in this RFC: Deprecate spreading key from objects.

Examples

Failing

import React from "react";

interface Foo = { key?: string; }

interface MyComponentProps extends Foo {
  className: string;
  children: React.ReactNode;
}

function MyComponent(props: MyComponentProps) {
  return <div {...props} />;
  //          ^^^^^^^^^^
  //          - This spread attribute implicitly passes the 'key' prop to a component, this could lead to unexpected behavior. If you intend to pass the 'key' prop, use 'key={value}'.
}

Passing

import React from "react";

interface Foo = { key?: string; }

interface MyComponentProps extends Foo {
  className: string;
  children: React.ReactNode;
}

function MyComponent({ key, ...rest }) {
  return <div {...rest} />;
}

Implementation


See Also