我正在尝试测试页面上的登录和注销链接,但是每当尝试执行window.dispatch(signup(user))
时,都会收到以下错误消息:
redux-logger.js:1 Uncaught Error: Actions may not have an undefined "type" property. Have you misspelled a constant?
我已经仔细检查了动作,对我来说很好:
export const RECEIVE_CURRENT_USER = 'RECEIVE_CURRENT_USER';
export const LOGOUT_CURRENT_USER = 'LOGOUT_CURRENT_USER';
export const RECEIVE_SESSION_ERRORS = 'RECEIVE_SESSION_ERRORS';
export const receiveCurrentUser = user => ({
type: RECEIVE_CURRENT_USER,
user
});
export const logoutCurrentUser = () => ({
type: LOGOUT_CURRENT_USER,
});
export const receiveSessionErrors = errors => ({
type: RECEIVE_SESSION_ERRORS,
errors
});
export const login = user => dispatch => (
APIUtil.login(user).then(user => dispatch(receiveCurrentUser(user)))
);
export const logout = () => dispatch => (
APIUtil.logout().then(() => dispatch(logoutCurrentUser())),
err => dispatch(receiveSessionErrors(err.responseJSON))
);
export const signup = user => dispatch => (
APIUtil.signup(user).then(user => dispatch(receiveCurrentUser(user))),
err => dispatch(receiveSessionErrors(err.responseJSON))
);
我还检查了我的reducer的注册情况,并且我认为自己正确导入了操作:
import {RECEIVE_CURRENT_USER, LOGOUT_CURRENT_USER} from '../actions/session_action';
const _nullUser = Object.freeze({
id: null
});
const sessionReducer = (state = _nullUser, action) => {
Object.freeze(state);
switch (action.type) {
case RECEIVE_CURRENT_USER:
return {id: action.currentUser.id};
case LOGOUT_CURRENT_USER:
return _nullUser;
default:
return state;
}
}
export default sessionReducer;
关于此错误为何突然出现或可能来自何处的任何想法?
更新:尽管出现了错误消息,但似乎用户注册已经通过,并且该用户确实在我的数据库中。但是当我在控制台上执行getState()
时,我创建的用户不会出现在状态中。
以下是错误消息的详细图片: