ES6 Failed propType
See original GitHub issueHi, I’m using the connector to a ES6 class. I get my data but a warning on the propType. “Warning: Failed propType: Required prop data
was not specified in Home
. Check the render method of Router
.”
I tried enabling es7.classProperties and move to static propTypes = … That got rid of the warning but I rather stay on ES6 and only the ES7 features that i really want (like es7.decorators). Any ideas?
@connect(state => ({
data: state.info
}))
export default class Info extends React.Component {
render() {
return (
<InfoComponent data={this.props.data}/>
);
}
}
Info.displayName = 'Info';
Info.propTypes = {
data: React.PropTypes.object.isRequired
};
Issue Analytics
- State:
- Created 8 years ago
- Reactions:4
- Comments:5 (1 by maintainers)
Top Results From Across the Web
Static propTypes not working under ES6 - Stack Overflow
Changed to use static but got this error: Warning: Failed prop type: Required prop name was not specified in App. – Pavel. Jul...
Read more >Typechecking With PropTypes - React
In this example, we're using PropTypes. string . When an invalid value is provided for a prop, a warning will be shown in...
Read more >How to validate React props using PropTypes - LogRocket Blog
Learn how to validate props with React PropTypes, React's internal mechanism ... If the validation fails, it should return an Error object.
Read more >prop-types - npm
import PropTypes from 'prop-types'; // ES6 var PropTypes ... It should return an Error // object if the validation fails.
Read more >How to Use PropTypes in React - freeCodeCamp
PropTypes are simply a mechanism that ensures that the passed value is of the correct datatype. This makes sure that we don't receive...
Read more >Top Related Medium Post
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@blesswinsamuel In regards to your example using static propTypes… Does that work for you? Using static propTypes as you have done there still gives me the same warning messages…
EDIT: I got it to work correctly with no warnings using the
connect
decorator andstatic propTypes
. My problem was babel related… I had thetransform-class-properties
plugin listed before thetransform-decorators-legacy
plugin.transform-decorators-legacy
must come beforetransform-class-properties
to be able to use theconnect
decorator andstatic propTypes
together (note that there are other issues that occur, entirely unrelated to redux, if you specify the order of the plugins incorrectly).Don’t use inheritance please 😃. I have never seen a justifiable case for it in React. I think the easiest way out is just not to use decorators in this case.