错误 'propTypes' 未定义且错误 'defaultProps' 未定义

error 'propTypes' is not defined and error 'defaultProps' is not defined

我正在处理 react-redux 应用程序的一些可访问性问题。

我安装了 npm install eslint eslint-plugin-jsx-a11y@4.0.0 --save-dev,现在当我 运行 我的应用程序时,我收到以下错误:

Failed to compile.

Error in ./src/components/Promo.jsx

/code/src/components/Promo.jsx
  15:10  error  'propTypes' is not defined       no-undef
  19:10  error  'defaultProps' is not defined    no-undef
  42:3   error  'updateCellCode' is not defined  no-undef

✖ 3 problems (3 errors, 0 warnings)

我没有看到任何语法错误,代码对我来说是正确的:

import React, { PureComponent, PropTypes } from 'react';
import { throttle, prepAndFormatForInnerHTML } from '../util';
import '../assets/styles/application/promo.css';
import Promos from '../assets/strings/promos.json'; // placeholder info

const MOBILE_BREAKPOINT = 679; // from scss file

/** Used in Account, App, and OrderStatus */
class Promo extends PureComponent {
  static propTypes = {
    hideOnSmall: PropTypes.bool,
  }

  static defaultProps = {
    hideOnSmall: false,
  }

  constructor() {
    super();

    this.updateCellCode = throttle(this.updateCellCode, 100);

    this.state = {
      cellCode: Promos[0].cellCodeWeb,
    };
  }

其他人能看出这里有什么问题吗?为什么我会收到这些错误?

PropTypes 现在是一个 separate 包(因为 React v15.5)。

所以不用

import { PropTypes } from 'react';

请使用

import PropTypes from 'prop-types';

实际错误如何 - 您可以尝试使用版本 3eslintsee more 关于这个)。