我遇到了一个问题:当样式数组通过props传递到某个组件时,它会重新渲染,但是样式不会改变。
我可以在React.Component中使用shouldComponentUpdate,但就我而言,最好使用PureComponent。
对此可以做什么?
示例:
<StyledComponent style={[styles.styleOne, styles.styleTwo]} />
StyledComponent:
export default class StyledComponent extends PureComponent {
render () {
return <View style={this.props.style} />
}
}
PureComponent不比较样式数组,而是重新渲染StyledComponent