Quantcast
Channel: Active questions tagged javascript - Stack Overflow
Viewing all articles
Browse latest Browse all 138163

Getting data from an API array in React

$
0
0

I have a React component that has to retrieve the items of an array containing objects that comes from an API. The array, favorites, is structured with items like this:

0:Object
  _id:Object
    ObjectId:"5db9cd4a1a088e7756516889"

where each of the items hold the id for a specific movie within a collection called movies. I have been trying to use map to get the data from this array with this piece of code:

{favorites.map(favorite =>
                      (<li key={favorite}>
                        <p className="favorites">
                          {JSON.parse(localStorage.getItem('movies')).find(movie => movie._id === favorite).title}

I have been failing miserably because I looked so much into this code. Could any of you throw some light in it? Any help is appreciated. Thanks in advance


Viewing all articles
Browse latest Browse all 138163

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>