I have a simple react app which pulls data from an API and prints it to the console. I'm using Axios to get the values from API. Here is the API: https://mobile-tha-server-8ba57.firebaseapp.com/walmartproducts/1/20
import React, { Component } from 'react';
import axios from 'axios';
class Products extends Component {
state = {
MetaProducts: []
}
async componentDidMount(){
const res = await axios.get('https://mobile-tha-server-8ba57.firebaseapp.com/walmartproducts/1/20')
this.setState({ MetaProducts: res.data.products});
}
render() {
console.log(this.state.MetaProducts);
return(
<div>
Products
</div>
)
}
}
export default Products;
But Axios, first returns an empty array and then returns the array with data.
console:
Products.js:14 []
Products.js:14 (20) [{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}]