我可以在 React.js 中更新组件的道具吗?
2022-08-30 00:22:49
在开始使用 React.js之后,它似乎是静态的(从父组件传入),而基于事件的更改。但是,我注意到文档中对组件WillReceiveProps
的引用,其中特别包括此示例:props
state
componentWillReceiveProps: function(nextProps) {
this.setState({
likesIncreasing: nextProps.likeCount > this.props.likeCount
});
}
这似乎意味着,根据 与 的比较,组件上的属性可以更改。我错过了什么?道具是如何变化的,或者我是否误以为道具被叫到哪里?nextProps
this.props