Skip to content

Instantly share code, notes, and snippets.

@r-mc2
Created January 17, 2019 17:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save r-mc2/0d62ef180ec6be8163a07782c32e948f to your computer and use it in GitHub Desktop.
Save r-mc2/0d62ef180ec6be8163a07782c32e948f to your computer and use it in GitHub Desktop.
Example React Component that shows the "no-typos" false-positive error with "eslint-plugin-react"
import React, { Component } from "react";
import { string, func } from "prop-types";
class Sample extends Component {
constructor(props) {
super(props);
this.state = {
newName: props.name
};
}
componentDidMount() {
if (this.state.name === "") {
this.setDefaultName();
}
}
setDefaultName = () => {
this.setState({ name: "Default"});
};
openHandler = () => {
this.props.clickHandler();
};
render() {
return (
<div>Hi!</div>
);
}
}
Sample.propTypes = {
// These three all trigger the false-positive
name: string.isRequired,
body: string.isRequired,
clickHandler: func.isRequired
};
export default Sample;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment