3
我是Promises和React的新手。我在我的動作創作者中使用了redux-thunk來解決承諾,我從組件中調用動作創建者。請求完成成功或失敗後,如何路由到其他網址?我附加了刪除函數動作創建者的代碼。如何在成功或錯誤後使用redux thunk重定向?
我應該在分派成功時用參數(routeTo)設置狀態嗎?
這裏的刪除功能:
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));
});
}
}
我打電話在我的組件一個onclick功能這一功能。
deletePost(){
this.props.deletePost(this.props.params.id);
}
謝謝!我打算爲這個減速器創建案例,但感覺太過分了。 –