gpt4 book ai didi

javascript - Prop 验证 react / Prop 类型中缺少

转载 作者:太空狗 更新时间:2023-10-29 15:27:58 26 4
gpt4 key购买 nike

  • 我是 js 新手。
  • 修复了其他无法修复 props lint 错误的 lint 错误
  • 我收到以下 lint 错误,用谷歌搜索无法找出问题所在的错误。17:20 Prop 验证 react / Prop 类型中缺少错误“playerLaughing”

  • 提供下面的代码

  • 你们能告诉我如何解决吗
C:\workspace\sports-dia-dashboard\src\components\sample-player\player-section.jsx
17:20 error 'playerLaughing' is missing in props validation react/prop-types
17:40 error 'id' is missing in props validation react/prop-types
23:9 warning Unexpected var, use let or const instead no-var
23:53 error 'jumping' is missing in props validation react/prop-types
28:32 warning There should be no space before '=' react/jsx-equals-spacing
28:32 warning There should be no space after '=' react/jsx-equals-spacing
30:37 error 'flying' is missing in props validation react/prop-types
33:21 warning Empty components are self-closing react/self-closing-comp
44:3 error Expected indentation of 4 spaces but found 2 indent



import React from 'react';


class Swimming extends React.Component {
constructor(props) {
super(props);
this.playerLaughing = this.playerLaughing.bind(this);
}

playerLaughing() {
//console.log("playerLaughing");
// debugger;
this.props.playerLaughing(this.props.id);
}

render() {
//console.log("render");
//console.log("accordion / the ExpandCollapse Section component");
var className = 'player-section' + (this.props.jumping ? ' jumping' : '');

return (
<div className={className} onClick={this.playerLaughing}>

<div className = "sports-player-question-flying sports-submenu-dropmenuHeader">
<h3>
{this.props.flying}
</h3>

<div className="up-arrow"></div>
</div>

<div className="body">
{this.props.children}
</div>


</div>
);

}

}


export default Swimming;

最佳答案

您需要在组件上设置静态属性“propTypes”以满足此 lint 错误。

这里是一些关于 React 的 PropTypes 的信息:React Docs

您将添加一个与此类似的部分:

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

class Swimming extends React.Component {
static propTypes = {
jumping: PropTypes.bool,
playerLaughing: PropTypes.func
};
constructor(props) {
...
}

您需要安装“prop-types”npm 包。

关于javascript - Prop 验证 react / Prop 类型中缺少,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43686253/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com