I'm a newbie to Promises and React. I'm using redux-thunk in my action creators to resolve promises and I'm calling the action creators from my component. How do I route to a different URL after successful or unsuccessful request completion? I'm attaching the code for a delete function action creator.
Should I set the state with a parameter (routeTo) when I dispatch it, on success?
Here's the delete function:
export function deletePost(id){
var request = axios.delete(`${ROOT_URL}posts/${id}${API_KEY}`);
return function(dispatch){
request.then((response)=>{
console.log("I deleted"+response.data.title);
}).catch((error)=>{
console.log("DELETE_ERROR: "+JSON.stringify(error));
});
}
}
I'm calling this function from an onclick function in my component.
deletePost(){
this.props.deletePost(this.props.params.id);
}