我正在使用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) 我有下一个代码,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)