Redux 在没有类型的情况下分派操作
我想发出一个行动Redux 在没有类型的情况下分派操作,redux,Redux,我想发出一个行动 export const signout = () => { return function (dispatch) { firebaseAuth.signOut() .then(() => dispatch(signOutSuccess())); }; } export const signOutSuccess = () => { type: SIGN_OUT_SUCCESS } 但是redux logger非常紧张,
export const signout = () => {
return function (dispatch) {
firebaseAuth.signOut()
.then(() => dispatch(signOutSuccess()));
};
}
export const signOutSuccess = () => {
type: SIGN_OUT_SUCCESS
}
但是redux logger非常紧张,因为它没有类型属性
redux-logger.js:1 Uncaught TypeError: Cannot read property 'type' of undefined
at redux-logger.js:1
at redux-logger.js:1
如何解决此问题?您的函数
signOutSuccess
不返回任何内容
试试那样的
export const signOutSuccess = () => {
return {type: SIGN_OUT_SUCCESS}
}
或者更简洁地说:
export const signOutSuccess = () => ({
type: SIGN_OUT_SUCCESS
})
似乎您没有在
signOutSuccess()函数中返回对象。你需要把花括号括起来
export const signOutSuccess = () => ({ type: SIGN_OUT_SUCCESS });
带有return
的冗长语句会降低出错的可能性。用那个。