【发布时间】:2018-04-08 01:00:44
【问题描述】:
我有这个:https://codesandbox.io/s/j3llymyxqw
而且我无法解释为什么它在注销时不起作用。
我按照教程学习了 react-redux 的做法。
为什么它不起作用?
authReducers.js:
import {
AUTHENTICATED,
UNAUTHENTICATED,
AUTHENTICATION_ERROR
} from "../actions/actionTypes";
export default function(state = {}, action) {
switch (action.type) {
case AUTHENTICATED:
return { ...state, authenticated: true };
case UNAUTHENTICATED:
return { ...state, authenticated: false };
default:
return state;
}
}
authActions.js:
import * as actionTypes from "./actionTypes";
export function loginAction(history) {
return async dispatch => {
const timeout = ms => new Promise(res => setTimeout(res, ms));
await timeout(1000);
....
dispatch({ type: actionTypes.AUTHENTICATED });
};
}
export function logoutAction(history) {
...
return { type: actionTypes.UNAUTHENTICATED };
}
【问题讨论】:
-
“它不工作”不是很有帮助。您具体预计会发生什么,具体会发生什么?
标签: reactjs react-native redux react-router react-redux