Tho*_*mas 2 javascript typescript reactjs redux
我的redux状态看起来像这样:
{
entities: {
cars: {
byId: {},
isFetching: true
},
persons: {
byId: {},
isFetching: false
}
}
}
Run Code Online (Sandbox Code Playgroud)
我的人员容器:
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)
);
Run Code Online (Sandbox Code Playgroud)
当我在entities.cars下的redux状态发生变化时,为什么我的Person容器会重新渲染?它是否应该触发渲染,因为'实体'已经改变了?GET_CARS操作设置entities.cars.isFetching = true.这是否会导致PersonComponent中的重新渲染?
state.entities.persons更新后可能是同一个对象cars,但_.values(state.entities.persons.byId)每次执行时都会生成一个新对象 - _.values即使输入保持不变,也不会缓存/重用其结果.
由于提供给它的道具PureComponent现在是一个不同的对象(即使内容相同),也会触发重新渲染.
| 归档时间: |
|
| 查看次数: |
71 次 |
| 最近记录: |