我通过运行prop-types安装了npm i prop-types --save包,我的依赖项是:
"dependencies": {
"prop-types": "^15.7.2",
"react": "^16.8.6",
"react-dom": "^16.8.6",
"react-scripts": "3.0.1"
},我的代码:
import React from 'react';
import PropTypes from 'prop-types';
function Question(props) {
return (
<h2 className="question">{props.content}</h2>
);
}
Question.propTypes = {
content: React.PropTypes.string.isRequired
};
export default Question;我重新启动节点5-6次,但仍然得到以下错误:

我在这里错过了什么?
发布于 2019-08-24 17:09:45
基于ReactJS文档/教程页面https://reactjs.org/docs/typechecking-with-proptypes.html,看起来您正在尝试使用旧方法访问PropTypes。
试着用这个代替:
Question.propTypes = {
content: PropTypes.string.isRequired
};发布于 2019-08-24 17:09:51
查看文档,您不需要React前缀:
Question.propTypes = {
content: PropTypes.string.isRequired
};https://stackoverflow.com/questions/57639972
复制相似问题