我原来的写法
import React, { Component, PropTypes } from 'react';
export default class CommonTitle extends Component {
render() {
return (
…
)
}
}
CommonTitle.propTypes = {
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 中引入
本文解决了一个关于在React组件中正确引入PropTypes的问题。原先作者尝试从React包中直接导入PropTypes但遇到错误,通过调整将PropTypes单独从'prop-types'包中导入解决了问题。
1万+

被折叠的 条评论
为什么被折叠?



