DEV Community

Mariusz
Mariusz

Posted on • Edited on

2

React tldr; Why Do I Need Keys in React List?

• Lists are performant heavy and need to be used carefully.

• Make sure every item in the list has a unique key.

• It is preferred to not use indexes as a key unless you know for sure that the list is a static list (no additions/re-ordering/removal to the list).

• Never use unstable keys like Math.random() to generate a key.

• React will run into performance degradation and unexpected behavior if unstable keys are used.

Source: https://medium.com/@adhithiravi/why-do-i-need-keys-in-react-lists-dbb522188bbb?fbclid=IwAR09xviOqDHRc7gvvoLXXDgVfVBtxbkCylq0p2Eur-jKrhw9EuMIpZ7c0BQ

Top comments (0)

nextjs tutorial video

Youtube Tutorial Series 📺

So you built a Next.js app, but you need a clear view of the entire operation flow to be able to identify performance bottlenecks before you launch. But how do you get started? Get the essentials on tracing for Next.js from @nikolovlazar in this video series 👀

Watch the Youtube series

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay