ReactJS “TypeError: Cannot read property 'array' of undefined”

前端 未结 4 792
感情败类
感情败类 2021-01-04 05:31

While running this code I got error on the first line on App.propTypes

TypeError: Cannot read property \'array\' of undefined

4条回答
  •  梦毁少年i
    2021-01-04 06:08

    Prop-Types are now a separately maintained library named prop-types Here is the explanation from react-docs: https://reactjs.org/docs/typechecking-with-proptypes.html

    You have to import them as

    import React from 'react';
    import PropTypes from 'prop-types'
    
    class App extends React.Component {
      //App here
    }
    
    App.propTypes = {
     propArray: PropTypes.array.isRequired, 
     propBool: PropTypes.bool.isRequired,
     propFunc: PropTypes.func,
     propNumber: PropTypes.number,
     propString: PropTypes.string,
     propObject: PropTypes.object
    }
    

    NPM Package

提交回复
热议问题