【发布时间】:2019-03-10 16:34:41
【问题描述】:
我正在尝试在我的第一个 react-native 应用程序中设置鸭子和传奇。但是每当我尝试调用鸭子函数时,我都会收到一个红屏提示:Cannot read property 'type' of undefined
Redux 存储正在创建,但不知道为什么它没有在 switch 案例中采取行动。
以下代码来自我的鸭子/auth.js
import { fromJS, List } from 'immutable';
const action = name => `/auth/${name}`;
export const LOGIN_REQUEST = action('LOGIN_REQUEST');
export const loginRequest = () => ({ type: LOGIN_REQUEST, });
export const FETCH_LOGIN_REQUEST = action('FETCH_LOGIN_REQUEST');
export const fetchLoginRequest = login => ({ type: FETCH_LOGIN_REQUEST, login });
const initialState = {
token: null,
}
const auth = (state = initialState, action) => {
console.log('Hello Action: ', action.type);
switch (action.type) {
case FETCH_LOGIN_REQUEST:
return state.set('token', action.login);
default:
console.log('Hello Auth Ducks Default')
return state;
}
};
export default auth;
【问题讨论】:
-
你的 console.log(action.type) 输出什么?我假设未定义?
-
@JRK 这是行动。类型控制台:@@redux/INITk.h.c.n.b.f
-
@JRK,看来
action是undefined,所以action.type抛出错误。你如何调用auth函数?删除了你的 console.log,评论你的开关,并给我们返回console.dir(action) -
Reducer “auth” returned undefined when handling “@@redux/INIT4.f.t.o.4” action. To ignore an action, you must explicitly return the previous state.卸下开关盒时出现以下错误。console.dir(action)是undefined -
@AlexandreT 您可以通过运行代码来检查它。
https://github.com/rajdeepratan/naiudaan
标签: react-native redux redux-form redux-thunk redux-saga