All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.sonar.l10n.javascript.rules.javascript.S6477.html Maven / Gradle / Ivy

There is a newer version: 10.17.0.28100
Show newest version

React expects a unique identifier key in list components to optimize rendering. Missing keys will negatively impact performance and can bring your application to a halt when there are enough elements. Avoid Array indexes since they are not stable. Instead, use a unique attribute like an ID or a combination of attributes.

Noncompliant Code Example

function Blog(props) {
  return (
    <ul>
      {props.posts.map((post) =>
        <li>
          {post.title}
        </li>
      )}
    </ul>
  );
}

Compliant Solution

function Blog(props) {
  return (
    <ul>
      {props.posts.map((post) =>
        <li key={post.id}>
          {post.title}
        </li>
      )}
    </ul>
  );
}

See





© 2015 - 2024 Weber Informatics LLC | Privacy Policy