当前位置: 首页 > 面试题库 >

在道具验证中缺少React eslint错误

梁丘霖
2023-03-14
问题内容

我有下一个代码,随便抛出:

反应/道具类型onClickOut; 道具验证中缺少

反应/道具型儿童;道具验证中缺少

propTypes 已定义,但eslint无法识别。

import React, { Component, PropTypes } from 'react';

class IxClickOut extends Component {
  static propTypes = {
    children: PropTypes.any,
    onClickOut: PropTypes.func,
  };

 componentDidMount() {
    document.getElementById('app')
      .addEventListener('click', this.handleClick);
  }

  componentWillUnmount() {
    document.getElementById('app')
      .removeEventListener('click', this.handleClick);
  }

  handleClick = ({ target }: { target: EventTarget }) => {
    if (!this.containerRef.contains(target)) {
      this.props.onClickOut();
    }
  };

  containerRef: HTMLElement;

  render() {
    const { children, ...rest } = this.props;
    const filteredProps = _.omit(rest, 'onClickOut');

    return (
      <div
        {...filteredProps}
        ref={container => {
          this.containerRef = container;
        }}
      >
        {children}
      </div>
    );
  }
}

export default IxClickOut;

package.json

{
  "name": "verinmueblesmeteor",
  "private": true,
  "scripts": {
    "start": "meteor run",
    "ios": "NODE_ENV=developement meteor run ios"
  },
  "dependencies": {
    "fine-uploader": "^5.10.1",
    "foundation-sites": "^6.2.3",
    "install": "^0.8.1",
    "ix-gm-polygon": "^1.0.11",
    "ix-type-building": "^1.4.4",
    "ix-type-offer": "^1.0.10",
    "ix-utils": "^1.3.7",
    "keymirror": "^0.1.1",
    "meteor-node-stubs": "^0.2.3",
    "moment": "^2.13.0",
    "npm": "^3.10.3",
    "rc-slider": "^3.7.3",
    "react": "^15.1.0",
    "react-addons-pure-render-mixin": "^15.1.0",
    "react-dom": "^15.1.0",
    "react-fileupload": "^2.2.0",
    "react-list": "^0.7.18",
    "react-modal": "^1.4.0",
    "react-redux": "^4.4.5",
    "react-router": "^2.6.0",
    "react-styleable": "^2.2.4",
    "react-textarea-autosize": "^4.0.4",
    "redux": "^3.5.2",
    "redux-form": "^5.3.1",
    "redux-thunk": "^2.1.0",
    "rxjs": "^5.0.0-beta.9",
    "rxjs-es": "^5.0.0-beta.9",
    "socket.io": "^1.4.8"
  },
  "devDependencies": {
    "autoprefixer": "^6.3.6",
    "babel-eslint": "^6.0.4",
    "babel-plugin-transform-decorators-legacy": "^1.3.4",
    "babel-preset-es2015": "^6.9.0",
    "babel-preset-react": "^6.5.0",
    "babel-preset-stage-0": "^6.5.0",
    "core-js": "^2.0.0",
    "cssnano": "^3.7.1",
    "eslint": "^2.12.0",
    "eslint-config-airbnb": "^9.0.1",
    "eslint-import-resolver-meteor": "^0.2.3",
    "eslint-plugin-import": "^1.8.1",
    "eslint-plugin-jsx-a11y": "^1.2.2",
    "eslint-plugin-react": "^5.1.1",
    "node-sass": "^3.8.0",
    "postcss-cssnext": "^2.6.0",
    "sasslets-animate": "0.0.4"
  },
  "cssModules": {
    "ignorePaths": [
      "node_modules"
    ],
    "jsClassNamingConvention": {
      "camelCase": true
    },
    "extensions": [
      "scss",
      "sass"
    ],
    "postcssPlugins": {
      "postcss-modules-values": {},
      "postcss-modules-local-by-default": {},
      "postcss-modules-extract-imports": {},
      "postcss-modules-scope": {},
      "autoprefixer": {}
    }
  }
}

.babelrc

{
  "presets": [
    "es2015",
    "react",
    "stage-0"
  ],
  "whitelist": [
      "es7.decorators",
      "es7.classProperties",
      "es7.exportExtensions",
      "es7.comprehensions",
      "es6.modules"
  ],
  "plugins": ["transform-decorators-legacy"]
}

.eslintrc

{
  "parser": "babel-eslint",
  "extends": "airbnb",
  "rules": {
    "no-underscore-dangle": ["error", { "allow": [_id, b_codes_id] }],
  },
  "settings": {
    "import/resolver": "meteor"
  },
  "globals": {
    "_": true,
    "CSSModule": true,
    "Streamy": true,
    "ReactClass": true,
    "SyntheticKeyboardEvent": true,
  }
}

问题答案:

问题出在handleClick中的流注释中,我删除了它,并且工作正常,谢谢@alik



 类似资料:
  • 我有一个组件叫 ESlint抱怨道具验证中缺少。 和SiteTechnologyForm用于其他组件,如下面的: 我最初尝试使用 但是当我尝试运行网页时,我在控制台中遇到了这个错误 检查类型。js:19警告:失败的道具类型:SiteTechnologyForm:道具类型无效;它必须是一个函数,通常来自包,但收到。 如果handleSubmit未通过验证,如何解决这种情况?

  • 问题内容: 我要求在通用api模块(多模块项目)中,我不能使用任何形式的hibernate的验证注释,因此我确实使用了javax.validation中的一个可接受的注释。 当我要验证包含NotBlank批注的域对象(我使用vaadin)时,问题就开始了。我得到以下异常 验证通过调用进行 相同的代码与hibernate的NotBlank完美配合 javax的@Size @NotNull也可以正常工

  • 我得到了以下错误无法构建Hibernate SessionFactory;嵌套异常是org.hibernate.tool.schema.spi.模式管理异常:模式验证:缺少表[my.table] 这有版本问题吗?大多数示例都不使用模式,即使是官方的?https://github.com/spring-projects/spring-boot/tree/main/spring-boot-tests/

  • 下面是XSD。 下面是xml文件。 当尝试使用http://www.utilities-online.info/xsdvalidation验证它时,我得到以下错误 第2行62:org.xml.sax.SAXParseException;行号:2;列号:62;CVC-ELT.1:找不到元素“Message”的声明。

  • 问题内容: 我使用Spring 4.3.3.RELEASE,Hibernate 5.2.2.Final,数据库是MySQL。我想尝试一下 strategy = GenerationType.TABLE 。正如我对 GenerationType.SEQUENCE 所知, 我需要数据库中的序列来生成ID。 这是我的实体。 Spring注解配置 Spring xml配置 当我运行我的应用程序时,我得到