解决ReactNative混合开发中,遇到undefined i
2017-10-26 本文已影响0人
会撸码的小马
报错undefined is not an object (evaluating '_react.PropTypes.string')问题

原因: 从 React v15.5 开始 ,React.PropTypes助手函数已被弃用,建议使用prop-types库来定义contextTypes。
所以,我们在开发中,不能直接从React引入PropTypes,即不能 import { PropTypes } from 'react';这样引用了
解决办法:
npm install --save prop-types
引入方式:
import PropTypes from 'prop-types';//ES6
var PropTypes = require('prop-types');//ES5 with npm