【发布时间】:2017-03-20 15:08:51
【问题描述】:
我有下一个对象:
Book = {
id: 1,
titel: "Some Book",
sections: [
{id: 1,
titel: "Section Titel",
pages: [
{id: 1, content: "Some text"},
{id: 2, content: "Some text"},
{id: 3, content: "Some text"}
]
},
{id: 2,
titel: "Section Titel",
pages: [
{id: 1, content: "Some text"},
{id: 2, content: "Some text"}
]
}
]
}
Book 对象存储在 Redux 存储区 (state.Book)。
我有可视化这个Book 对象的组件。
组件Book 渲染一个或多个Section 组件,每个Section 组件渲染Page 组件。
Book 通过 react-redux 的 connect 函数订阅 Redux 并监听 store.Book,孔对象。
很明显,当Book 的titel 发生变化时,孔Book 对象将被重新渲染,包括所有Sections 和Pages。
有两个问题:
如果只更改了
Book.titel,React 引擎是否真的会重新渲染Sections和Pages?或者它会识别出组件的其他部分没有改变并且不会重新渲染它们。如果它会重新渲染,那么避免它的最佳方法是什么?我也应该订阅
Section和Page组件到Store吗?但这并不能解决问题,因为Book侦听孔state.Book对象。或者我应该只订阅Book组件到state.Book.id和state.Book.titel,然后在内部使用this.context.store将数据路径到内部组件?
提前致谢。
【问题讨论】:
标签: reactjs redux react-redux