【发布时间】:2017-10-08 17:37:07
【问题描述】:
我正在尝试执行异步发布请求以仅在成功后更新我的数据。
我想要的是在行动调用中使用承诺类型的东西。
this.props.postAction('/event/user/44/post',data)
.then((response) =>{
console.log("Inside callback");
console.log(response);
});
export default connect({postAction})(EventFeed);
这是我正在发出发布请求的操作文件
export const POST_ACTION = 'POST_ACTION';
export function postAction(url,data) {
return function(dispatch) {
axios({
method:'post',
url:API_URL + url,
headers: {'event': 55},
data: data,
})
.then(response => {
dispatch({
type: POST_ACTION,
payload: response.data
});
})
.catch((error) => {
console.log(error);
})
}
}
但我永远不会进入回调。
现在如何进行回调以从响应中获取数据???
【问题讨论】:
标签: api reactjs redux axios redux-thunk