斯蒂芬大帝
2018-08-13 09:09:14
為什么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);
1 回答
阿波羅的戰車
TA貢獻1862條經驗 獲得超6個贊
因為校驗只在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'?
添加回答
舉報
0/150
提交
取消
