Created
January 17, 2019 17:15
-
-
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"
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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