I have called an api which gives me somewhat of a response like this,
manufacturers: [{,…}, {,…}, {,…}, {,…}, {,…}, {,…}, {,…}, {,…}, {,…}, {,…}]
0: {,…}
1: {,…}
2: {,…}
3: {,…}
4: {,…}
5: {,…}
6: {,…}
7: {,…}
8: {,…}
9: {,…}
then I stored this in an array, which is like this (in console this gives me a single element array, which has an array of 10 elements ):
const arrOfProducts = [];
axios
.get(url)
.then((response) => {
arrOfProducts.push(response.data.result.manufacturers);
console.log(arrOfProducts); //in console this gives me a single element array, which has an array of 10 elements
})
.catch((error) => {
console.log(error);
});
Then I tried to map it in my React component Like this:
<Box
display='flex'
flexDirection='row'
alignItems='center'
justifyContent='space-evenly'
>
{arrOfProducts.map((items,index)=>{
return <Box key={index}>{items.city}</Box> //it has multiple keys like city,name etc
})}
</Box>
which doesn't render anything. Please tell me what I am doing wrong. Also please can suggest a better approach than this to store an api.