I have a react function as shown below:
const requestSideBarData = (state, request) => {
let newState = state;
Object.keys(newState.data).forEach(element => {
axios.post(`${ApiEndPoints.getDropDownHeaders}${element}`,request)
.then(response => {
newState.data[element] = response.data;
})
.catch(e => {
console.log(e);
});
});
return newState;
};
I want to return the newState after all the post response has been recieved and newState has been updated. How should I go about it? Since the function runs syncly it returns the same state without letting axios complete its response.