相关疑难解决方法(0)

如何在文件中禁用ESLint react/prop-types规则?

我正在使用React和ESLint与eslint-plugin-react.我想在一个文件中禁用prop-types规则.

var React = require('react'); 
var Model = require('./ComponentModel');

var Component = React.createClass({
/* eslint-disable react/prop-types */
    propTypes: Model.propTypes,
/* eslint-enable react/prop-types */
    render: function () {
        return (
            <div className="component">
                {this.props.title}
            </div>
        );
    }
});
Run Code Online (Sandbox Code Playgroud)

reactjs eslint

54
推荐指数
6
解决办法
5万
查看次数

道具验证中缺少React eslint错误

我有下一个代码,eslint throw:

反应/道具类型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 …
Run Code Online (Sandbox Code Playgroud)

javascript reactjs eslint flowtype

35
推荐指数
7
解决办法
6万
查看次数

标签 统计

eslint ×2

reactjs ×2

flowtype ×1

javascript ×1