Having a response issue.
When making an ajax call to retrieve data from the backend i retrieve the data, but it appears that it retrieves the data only if its wrapped in a .then()
. Outside of a .then()
then the data clears out.
consume is a personal module that handles axios calls.
here is the issue
componentWillMount() {
const retrieveLogs = {
method: "GET",
url: this.state.url,
}
consume.fetch(retrieveLogs)
.then(res => {
if(typeof res.logger === "object"){
this.setState({
logs: res.logger,
})
console.log(this.state.logs) // show the console log here but
}
})
console.log(this.state.logs) // but shows empty array here why is this ?
}