How to fix React 15.5.3 PropTypes deprecated warning when using create-react-app

后端 未结 2 636
悲哀的现实
悲哀的现实 2020-12-14 18:54

I\'m using create-react-app to start React project. At latest React 15.5.3 package, it appears following warnings:

Warning:

相关标签:
2条回答
  • 2020-12-14 19:16

    Pulled from Reacts blog - npm install prop-types, then use new code. Also it said you can get this error message if a nested component is not using prop-types but the parent is - so you need to check other components.

    // Before (15.4 and below)
    import React from 'react';
    
    class Component extends React.Component {
      render() {
        return <div>{this.props.text}</div>;
      }
    }
    
    Component.propTypes = {
      text: React.PropTypes.string.isRequired,
    }
    
    // After (15.5)
    import React from 'react';
    import PropTypes from 'prop-types';
    
    class Component extends React.Component {
      render() {
        return <div>{this.props.text}</div>;
      }
    }
    
    Component.propTypes = {
      text: PropTypes.string.isRequired,
    };
    
    0 讨论(0)
  • 2020-12-14 19:34

    React v15.5.x adds new warnings check here

    Downgrading React v15.5.3 to 15.4.x works for me

    npm install --save react@15.4.0 react-dom@15.4.0
    
    0 讨论(0)
提交回复
热议问题