关于React组件类的propTypes属性

为什么console没有提示信息??

var MyTitle = React.createClass({        propTypes:{            title:React.PropTypes.isRequired,
        },        render:function(){            return <h1>{this.props.title}</h1>;
        }
    });var data = 10;

ReactDOM.render(<MyTitle />,document.body);


斯蒂芬大帝
浏览 735回答 1
1回答

阿波罗的战车

因为校验只在development mode中生效:As your app grows it's helpful to ensure that your components are used correctly. We do this by allowing you to specify propTypes. React.PropTypes exports a range of validators that can be used to make sure the data you receive is valid. When an invalid value is provided for a prop, a warning will be shown in the JavaScript console. Note that for performance reasons propTypes is only checked in development mode看文档:Prop Validation至于如何开启/禁用development mode,看这里:How to turn on/off ReactJS 'development mode'?
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript