简体   繁体   中英

Bad Errors for PropType (React)

My code seems to be throwing incorrect PropType errors.

SomeComponent = React.createClass({
    propTypes: {
        someFunction: React.PropTypes.func.isRequired
    },
...});

SomeOtherComponent = React.createClass({
    internalFunction: function(){
        console.log('test!');
    },
    render: function(){
        return <SomeComponent someFunction={this.internalFunction}/>
    }
...});

Getting that console.log to trigger isn't a problem at all, but I'm getting a prop type mismatch error on the func in the console as soon as the page loads.

How is it possible to have an error message and have access to the function?

Found the issue.

Had func.required instead of func.isRequired on the propTypes and just completely overlooked it. ah well.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM