Daniel
Daniel

Reputation: 15413

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

I am working on some accessibility issues on a react-redux application.

I installed npm install eslint [email protected] --save-dev and now when I run my application I get the following errors:

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?

Upvotes: 2

Views: 2480

Answers (1)

falinsky
falinsky

Reputation: 7428

PropTypes now is a separate package (since 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).

Upvotes: 6

Related Questions