Category: Next.js, React and TypeScript

React: Encountered two children with the same key in the record list

Read this guide in Polish

After updating or filtering the list items are wrong and the console warns about identical keys. React uses key to preserve the element identity; two records with the same key break this match.

How to determine the source of the error

Compare the IDs returned from the API and the values used as key when mapping the list.

Check that the same position is not added twice as a result of pagination or unidentifiable fetch.

What to do step by step

1. Select a stable unique identifier from the data, and when it is missing, repair the data model or remove the actual duplicate.

2 . When paging, link results by ID, not by blindly pasting all responses.

How to check the score

After filtering, sorting and updating, each item retains the correct identity and condition.

What to do

Do not use Math.random() or array index to a dynamic list that changes order.