【发布时间】:2014-09-16 08:34:45
【问题描述】:
开始使用 React.js 后,props 似乎是静态的(从父组件传入),而 state 根据事件发生变化。但是,我注意到文档中提到了componentWillReceiveProps,其中特别包括了这个例子:
componentWillReceiveProps: function(nextProps) {
this.setState({
likesIncreasing: nextProps.likeCount > this.props.likeCount
});
}
这似乎意味着可以根据nextProps 与this.props 的比较来更改组件的属性。我错过了什么? props 是如何变化的,还是我弄错了它的调用位置?
【问题讨论】:
标签: javascript reactjs properties