简体   繁体   English

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

[英]error 'propTypes' is not defined and error 'defaultProps' is not defined

I am working on some accessibility issues on a react-redux application. 我正在研究react-redux应用程序的一些可访问性问题。

I installed npm install eslint eslint-plugin-jsx-a11y@4.0.0 --save-dev and now when I run my application I get the following errors: 我安装了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)

I do not see any syntax errors and the code looks right to me: 我没有看到任何语法错误,代码看起来对我来说:

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,
    };
  }

Can anybody else see what is wrong here? 其他人可以看到这里有什么问题吗? Why am I getting these errors? 为什么我会收到这些错误?

PropTypes now is a separate package (since React v15.5 ). PropTypes现在是一个单独的包(自React v15.5 )。

So instead of 而不是

import { PropTypes } from 'react';

please use 请用

import PropTypes from 'prop-types';

What about actual error - you can try to use the eslint of version 3 ( see more about this). 实际错误怎么样 - 您可以尝试使用版本3eslint请参阅更多相关信息)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM