I want to push some data into a variable that is held outside of a axios promise method. But it does not allow me to do so.
export default function () {
let storage = []
axios.get('http://localhost:3001/api/content')
.then(res => {
let posts = res.data.map(obj => obj);
storage.push({posts});
})
return storage
}
Can anyone help me out with this. Also in terms of the long term. What is the best way to place api data into a reducer for react/redux. I am learning redux and trying to figure out how to do this the best way. It seems my above method is not ideal? Thanks.