我希望一个组件从其父组件接收其初始数据,同时仍然能够自行对数据进行分页。
例如,考虑
<Parent> //Makes initial GraphQL call
<StaticChild/> //Uses initial data and never needs to rerender
<DynamicChild/> //Paginates the same query that the Parent made, will need to rerender for every new "page"
</Parent>
会是什么样<DynamicChild>
子?我的理解是,为了能够访问 fetchMore (用于分页),您必须包装<DynamicChild>
函数graphql
(来自 react-apollo)。但是该graphql
功能需要初始查询,而<DynamicChild>
无需进行。我的选择似乎是:
a) 有<Parent>
句柄分页。这意味着我必须将 shouldComponentUpdate 方法添加到<StaticChild>
.
b)<DynamicChild>
进行了类似的初始查询,<Parent>
并依赖 Apollo 从 Redux 存储中提取第二个查询(假设这两个查询没有被批处理在一起)。
c)<Parent>
进行初始查询并将 fetchMore() 回调传递给<DynamicChild>
. 我担心在<DynamicChild>
使用回调时,它仍然会尝试重新渲染<Parent>
.
虽然这些解决方案很简单,但有没有办法在<DynamicChild>
不定义自己的初始查询的情况下定义自己的分页查询?