升级react版本后,使用npm 启动项目报错Cannot read property ‘string’ of undefined
报错信息
解决方式
在React v15.5 版本后prop-type不在react包中,需要加载prop-types包
原来代码:
import React,{ Component } from 'react';
...
const propTypes = {
stateContent: React.PropTypes.isRequired,
}
修改代码:
import PropTypes from 'prop-types';
...
const propTypes = {
stateContent: PropTypes.string.isRequired,
}
项目运行正常
参考资料
https://stackoverflow.com/questions/44573199/cannot-read-property-string-of-undefined-react-proptypes-layoutproptypes-j