I am sending data (string) from the dispatch function and want to return the object which was returned as a result of the POST request, but since axios works asynchronously, the return statement is executed before the POST request's result. Plz help
dispatch({ type: "INCREASE_VOTES_QUESTION", payload: loginUser.id })
export default function reducer(state, action) {
if (action.type === "INCREASE_VOTES_QUESTION") {
let updatedSingleQuestion
axios({
method: "POST",
url: `http://localhost:5000/questions/${question_id}/votes-update`,
withCredentials: true,
data: { action: "increase", id: action.payload },
}).then((res) => {
updatedSingleQuestion = res.data
})
return updatedSingleQuestion
}
}