[英]Why does my redux container render when unrelated state changes?
My redux state looks like this: 我的redux状态如下所示:
{
entities: {
cars: {
byId: {},
isFetching: true
},
persons: {
byId: {},
isFetching: false
}
}
}
My Person container: 我的人容器:
class PersonPageComponent extends React.PureComponent<
IPersonPageProps & InjectedAuthRouterProps,
{}
> {
render() {
console.log('render´);
return (<p>helllo</p>);
}
}
const mapStateToProps = (state: RootState, ownProps: { title: string }) => ({
list: _.values(state.entities.persons.byId), // personsSelector(state)
});
export const PersonPage = userIsAuthenticated(
connect<IPersonPageProps, {}, {}>(
mapStateToProps
)(PersonPageComponent)
);
Why does my Person container re-render when I have changes in redux state under entities.cars? 当我在entity.cars下的redux状态发生更改时,为什么我的Person容器会重新渲染? Is it supposed to trigger render since 'entities' changed?
自“实体”更改以来,是否应该触发渲染? A GET_CARS action sets entities.cars.isFetching = true.
GET_CARS操作设置entity.cars.isFetching = true。 Should this result in a re-render in PersonComponent?
是否应该导致PersonComponent中的重新渲染?
state.entities.persons
may be the same object after updating cars
, but _.values(state.entities.persons.byId)
produces a new object with each execution – _.values
does not cache/reuse its result, even if the input stays the same. 更新
cars
, state.entities.persons
可能是同一对象,但是_.values(state.entities.persons.byId)
每次执行_.values
产生一个新对象_.values
不会缓存/重用其结果,即使输入保持不变。
Since the prop provided to the PureComponent
is now a different object (even with identical content), a re-render is triggered. 由于提供给
PureComponent
的prop现在是一个不同的对象(即使具有相同的内容),因此将触发重新渲染。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.