I'm trying to fecthing all API which contain in array. I use promise all to get the data and I finally get the data that I wanted. But, I have a problem to store result into new array or object from Promise.all function. How I can store data from API on stateless component in React. So the expectaion in this approch I can call it like {dataJSON.title}
import React from 'react'
const ApiComponent = (props) => {
// props.film content
//["https://swapi.co/api/films/2/","https://swapi.co/api/films/6/"]
let dataJSON = []
Promise.all(
props.film.map(url =>
fetch(url)
.then(response => response.json())
.then(
parseJSON => ({
title: parseJSON.title,
episode: parseJSON.episode
})
)
.then(
dataJSON => push[dataJSON]
)
))
return (
// expecting return will call like this
{
dataJSON.title
}
)
}
export default ApiComponent;