react项目导入PropTypes报错: Typo in static class property declaration react/no-typos

在学习react的时候,测试props验证的时候,一直卡在的propTypes使用出错

import React from 'react';
import ReactDOM from 'react-dom';
import PropTypes from 'prop-types';

...

// props验证
var title = "菜鸟驿站";
class MyTitle extends React.Component{
	render(){
		return(
			<h1>Hello,{this.props.title}</h1>
		);
	}
}

MyTitle.PropTypes = {
	title: PropTypes.string
};

ReactDOM.render(
	<MyTitle title={title} />,
	document.getElementById('example')
)

怎么改都报以下错误: 

Failed to compile.

./src/index.js
  Line 270:9:  Typo in static class property declaration  react/no-typos

Search for the keywords to learn more about each error.

百思不得其解,因为都是自学。第一次,找到一个全英回答,看都没看就关了。又改了一阵子,还是改不了,又去看了那篇全英的问答,才发现,原来就是我粗心了。就是单纯大小写的问题。应该是propTypes而不是PropTypes。 

import React from 'react';
import ReactDOM from 'react-dom';
import propTypes from 'prop-types';

...

// props验证
var title = "菜鸟驿站";
class MyTitle extends React.Component{
	render(){
		return(
			<h1>Hello,{this.props.title}</h1>
		);
	}
}

MyTitle.propTypes = {
	title: propTypes.string
};

ReactDOM.render(
	<MyTitle title={title} />,
	document.getElementById('example')
)

搞定。

全英解析:https://stackoverflow.com/questions/62203534/typo-in-static-class-property-declaration-react-no-typos

  • 12
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 8
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 8
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值