I want to update a list which is defined outside of a promise (API call).
here is the code:
let data = [];
api.getData(this.state.ID).then((resp) => {
data = [...data, { title : resp.title }];
data = [...data, { name : resp.name }];
});
console.log(data); // --> it returns []
the data is [ ] and no value have pushed to it. how can I change my code to fix this issue? for some reasons I don't want to use setState()
Regards.