【发布时间】:2017-11-11 09:09:55
【问题描述】:
这是我收到的错误无法读取未定义的属性“数据”
switch (action.type){
case REGISTER_USER:
console.log("Action ", action);// This prints {type: "REGISTER_USER", payload: undefined}
return [action.payload.data, ...state];
}
return state;
我认为这是因为Promise {[[PromiseStatus]]: "pending", [[PromiseValue]]: undefined}
是承诺的当前状态。
这是我的行动
function registerUser(details, callback) {
console.log(details);
const request = axios.post(URL, {
"email": details['email'],
"name": details['username'],
"password": details['password']
}).then(() =>callback());
console.log(request);
return{
type: REGISTER_USER,
payload: request
};
}
正在传递的回调如下所示
onFormSubmit(values){
this.props.registerUser(values
,() =>{
this.props.history.push("/login");
}
);
}
我的问题是如何仅在 Promise 解决后才返回操作?我是初学者,在必要时做出反应纠正我。
【问题讨论】:
-
我建议从文档的 Asynchronous Actions 部分以及 'real world' example 开始。
标签: javascript reactjs promise react-redux