React的关键内部对象
props
这个是由调用这个组件的时传进来的参数。
//在MainMenu中获取这些值得时候就是用this.props.refreshData(),this.props.height,this.props.onClick
<MainMenu refreshData={ this.state.isRefreshMenu} height={ menuHeight} onClick={ this.clickMenu.bind(this)}/>
声明
static propTypes = {
searchFields: React.PropTypes.array,
onSearch: React.PropTypes.func
};
如果上面调用的时候改变了props的时候怎么告知子部件呢?
1.因为props改变的时候子部件调用了render()方法,可以直接在render里面去读用props的值。
2.在改变props时会触发子部件的componentWillReceiveProps
的方法。
\\nextProps就是改变后的props,如果return false