简体   繁体   English

ESLint:道具验证中缺少“handleVar”(反应/道具类型)

[英]ESLint: 'handleVar' is missing in props validation(react/prop-types)

I am working on a project using React and eslint but I got the following error:我正在使用 React 和 eslint 开发一个项目,但出现以下错误:

ESLint: 'handleVar' is missing in props validation(react/prop-types)

Here is my code:这是我的代码:

const Test = (props) => {
 
  return (
        <div className="form-inline row" style={{ marginRight: '10px' }}>
          <Select placeholder="Test" id="6" handleVar={props.handleVar} />
        </div>
  );
};

export default Test;

Do you know how can I solve that?你知道我该如何解决吗?

Thank you very much !非常感谢 !

You got that error because you don't use a Type Checking Library like PropTypes, TypeScript or Flow.你得到这个错误是因为你没有使用像 PropTypes、TypeScript 或 Flow 这样的类型检查库。

More info about the error:有关错误的更多信息:

React recommend to use TypeScript or Flow instead of PropTypes but here is a working example with PropTypes: React 建议使用 TypeScript 或 Flow 而不是 PropTypes ,但这里是 PropTypes 的一个工作示例:

import PropTypes from 'prop-types';

const Test = (props) => {
 
  return (
        <div className="form-inline row" style={{ marginRight: '10px' }}>
          <Select placeholder="Test" id="6" handleVar={props.handleVar} />
        </div>
  );
};

Test.propTypes = {
  handleVar: PropTypes.func
};

export default Test;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM