question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ES6 Failed propType

See original GitHub issue

Hi, 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:closed
  • Created 8 years ago
  • Reactions:4
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

60reactions
joshmandersoncommented, Aug 17, 2016

@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 and static propTypes. My problem was babel related… I had the transform-class-properties plugin listed before the transform-decorators-legacy plugin.

transform-decorators-legacy must come before transform-class-properties to be able to use the connect decorator and static propTypes together (note that there are other issues that occur, entirely unrelated to redux, if you specify the order of the plugins incorrectly).

19reactions
gaearoncommented, Jul 17, 2015

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.

class Info extends React.Component {
    render() {
        return (
            <InfoComponent data={this.props.data}/>
        );
    }
}

Info.displayName = 'Info';
Info.propTypes = {
    data: React.PropTypes.object.isRequired
};

export default connect(state => ({
    data: state.info
}))(Info)
Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found