React Native Undefined is not an object(evaluating ‘_react2.PropTypes.func’)

女爷i 2022-06-02 07:42 305阅读 0赞

我原来的写法

import React, { Component, PropTypes } from ‘react’;

export default class CommonTitle extends Component {

  1. render() \{
  2. **return** (
  3. )
  4. \}

}

CommonTitle.propTypes = {

  1. onTitleClick: PropTypes.func.isRequired

}

PropTypes 放在了react 中引入,但是还是出错

Undefined is not an object(evaluating ‘_react2.PropTypes.func’)

正确写法:

import React, { Component } from ‘react’;

import PropTypes from ‘prop-types’;

把PropTypes 从prop-types 中引入

发表评论

表情:
评论列表 (有 0 条评论,305人围观)

还没有评论,来说两句吧...

相关阅读

    相关 react native

    React Native使你能够在Javascript和[React][]的基础上获得完全一致的开发体验,构建世界一流的原生APP。 React Native