๐Ÿšจ Each Child Should Have Unique Key Prop ๐Ÿšจ

๐Ÿšจ Each Child Should Have Unique Key Prop ๐Ÿšจ

ยท

1 min read

Table of contents

No heading

No headings in the article.

Let's solve the react know issue that each child should have a unique key

Most of you got the above error while listing items in react. I know most of you say we can use id as a key for rendering unique child elements.

Now, what if we don't get the id in the API response??

Now some cool developers will say we can use the most famous npm package https://www.npmjs.com/package/uuid .

Now the issue with this above solution is that it confuses React, Whenever the component renders the id changed the reason for that is react calls the UUID function again and again whenever the component re-renders.


Episode 1 Nbc GIF by Law & Order

Here is the solution to the above problem. Try it by yourself you will love it. :)

I hope you learn something new today :). For more learn from here https://legacy.reactjs.org/docs/react-api.html


Thanks a lot for reading till the end ๐Ÿ™ You can contact me in case if you need any assistance:

Email: atul19251@gmail.com

Web: https://iamatul.netlify.app/

GitHub: https://github.com/iamrajput

LinkedIn:https://www.linkedin.com/in/atul-kumar-singh-673357102/

ย