My React组件具有一个prop类,它是基于来自redux存储库的数据的类实例。React类实例prop阻止使用PureComponent
原因是使用类及其所有自定义方法(超过50个)处理此数据要方便得多。
我无法使用PureComponent,因为React始终认为此道具已更改。问题是,我的React组件大部分都连接到这个支持...
我知道解决方案像重新选择,但这意味着有太多(我的类有自定义方法多)选择器只用于操作的这些数据。
你会建议什么?
我Redux的选择看起来是这样的:
getStation(state) {
// some logic to fetch the right station
return new WeatherStation(state.services.stationList[i])
}
其中气象站是:
class WeatherStation {
constructor (data) {
this.station = data
}
getId() {...}
// many more methods
}
和我的阵营Compoonent内:
class MyComponent extends React.Component {
...
const mapStateToProps = (state, ownProps) => {
return {
station: getStation(state),
}
}
}
你可以发布你的代码的相关部分? –
你有没有试过ImmutableJS? – hawk
还想看代码。特别是你创建你的类实例的地方。 – jonahe