我知道这个特定的错误已经无数次出现,但是我面临的问题似乎与其他错误有所不同。我正在使用Easy-peasy进行状态管理,存储模型如下所示:
//index.js of model
import { effect } from 'easy-peasy';
export default {
session: {
sessionChecked: (state, payload) => {
state.isSessionChecked = true;
},
login: effect(async (dispatch, { payload, push, to }) => {
if (!payload || Object.keys(payload).length === 0) {
dispatch.session.sessionChecked(); //This is the line that causes error
} else {
try {
dispatch.session.submit();
const response = await loginService(payload);
const data = await response.json();
localStorage.setItem('UserLoginInfo', JSON.stringify({ userInfo: payload, token: data.token }));
dispatch.session.loginSucceeded(data);
if (push && to) {
await dispatch.session.route({ push, to });
}
} catch (err) {
dispatch.session.loginFailed(err);
}
}
}),
},
};
然后这样称呼:
//index.js
function Root() {
return (
<StoreProvider store={store}>
<App />
</StoreProvider>
);
}
ReactDOM.render(<Root />, document.getElementById('root'));
我尝试将[]
作为第二个参数传递给登录效果函数,但问题仍然存在。