【问题标题】:Actions may not have an undefined "type" property动作可能没有未定义的“类型”属性
【发布时间】:2018-02-04 03:38:25
【问题描述】:

我正在使用react nativeredux,这是我的操作:

import EMPLOYEE_UPDATE from './types';

export const employeeUpdate = ({ prop, value }) => {
  return (
    {
      type: EMPLOYEE_UPDATE,
      paylaod: { prop, value }
    }
  );
};

但我得到这个错误:

Actions may not have an undefined "type" property. Have you misspelled a constant?

编辑: types.js 文件是:

export const LOGIN_USER_FAILED = 'loing_user_failed';
export const SHOW_SPINNER = 'show_spinner';
export const EMPLOYEE_UPDATE = 'employee_update';

【问题讨论】:

  • 你能用types文件编辑你的问题吗?

标签: reactjs react-native react-redux


【解决方案1】:

您需要像这样从types 文件中导入EMPLOYEE_UPDATE

import { EMPLOYEE_UPDATE } from './types';

【讨论】:

  • @farmcommand2 Redux 不知道您是否正确导入它。它所知道的是type 是未定义的,这就是它显示的错误。我认为这是 redux 能给你的最好的错误。
【解决方案2】:

您需要将 const 导入为命名导入而不是默认导入,因为您已将其导出为命名 const。

 import {EMPLOYEE_UPDATE} from './types';

有关命名和默认导出的详细信息,请参阅此答案:

in reactjs, when should I add brackets when import

【讨论】:

  • 但我们可以将() 放在通过return 返回的任何内容周围,对吗??
  • 知道为什么这个错误 meeasge 有那么大的误导性吗?
  • 不,这不是误导。它说该类型属性具有误导性。意味着您的 const 未正确导入,当您查看它的导出方式时会看到这一点
猜你喜欢
  • 2022-01-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-12-23
相关资源
最近更新 更多