Understanding unique keys for array children in React.js

后端 未结 12 1289
时光取名叫无心
时光取名叫无心 2020-11-21 05:45

I\'m building a React component that accepts a JSON data source and creates a sortable table.
Each of the dynamic data rows has a unique key assigned to it but I\'m stil

12条回答
  •  清酒与你
    2020-11-21 06:29

    Best solution of define unique key in react: inside the map you initialized the name post then key define by key={post.id} or in my code you see i define the name item then i define key by key={item.id}:

    {posts.map(item =>(
    {item.name}

    {item.username}

    {item.email}

    ))}

提交回复
热议问题