【发布时间】:2019-12-18 01:23:09
【问题描述】:
我收到了错误:
Actions must be plain objects. Use custom middleware for async actions.
我尝试了以下 Stack Overflow 问题中的解决方案,但没有奏效:
React-Redux: Actions must be plain objects. Use custom middleware for async actions
动作
export async function signupp(data){
console.log('In signupp:');
try{
const request = await axios({
method:'POST',
url:'http://192.168.1.10:3003/users/signup',
data:{
email:data.email,
password:data.password
},
}).then(response=>{
console.log(response.data);
return response.data
}).catch( e => {
console.log(e);
return false
});
return {
type:'signup',
payload:request
}
}
catch(e) {
console.log(e);
return false;
}
}
减速器
export default function(state={},action){
switch(action.type){
case 'signup':
return {
...state,
auth:{
email: action.payload.email,
password:action.payload.password
}
}
}
}
商店
const createStoreWithMiddleware = applyMiddleware()(createStore);
const appRedux = () => (
<Provider store = {createStoreWithMiddleware(reducers)}>
<App/>
</Provider>
)
AppRegistry.registerComponent(appName, () => appRedux);
顺便说一句,我在日志中得到了正确的响应。
【问题讨论】:
标签: react-native redux react-redux