React·100 questions

How to properly write keys and identifiers for components?

Answer
key is only needed for lists.
Use stable IDs from data.
Don't use random/Date.now for key.
Don't use index if items can move/delete.
Bad key breaks local state preservation.
Was this answer helpful?

More questions in this topic

Related questions from other topics