Redux和React-Naitve:无法读取未定义的属性'type'

时间:2018-10-05 08:04:01

标签: react-native redux redux-form redux-thunk redux-saga

我想在我的第一个本机应用程序中设置鸭子和野鹿。但是,每当我尝试调用Duck函数时,都会出现红色屏幕:无法读取未定义的属性'type'

Cannot read property 'type' of undefined

Redux存储正在创建中,但不知道为什么在切换情况下它不采取行动。

以下代码来自我的ducks / 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;

1 个答案:

答案 0 :(得分:1)

在welcome.js中更改

C<pair<const int, int>>

import loginRequest from '../ducks/auth.js';

import {loginRequest} from '../ducks/auth.js';是命名导出,而不是默认导出。