javascript – Correctly Map API response in react.js

You have the right idea of using .map to render a list of items, but you also need to make sure, that when you do this, that each returned item in the .map function, has a key attribute that must be unique inside the parent node.

If you’re calling data from an api, this will usually be inside the entry object as _id, id, or uuid, etc.

Beyond this, how you render this list depends on the data structure of each entry in response data.

The following is an example, if was an array of entries that took this form {id: uuid, text: string}

          //here's where i want to map the values.
         {this.props.state?.map((entry, idx)=>{
            return <div key={}>{entry.text}</div>

Read more here: Source link