0

我希望一个组件从其父组件接收其初始数据,同时仍然能够自行对数据进行分页。

例如,考虑

<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>不定义自己的初始查询的情况下定义自己的分页查询?

4

1 回答 1

0

作为重新获取功能的示例,您可以查看使用 GraphQL 和 apollo 客户端制作的应用程序的提要页面(提要页面)。

截至b)我认为它会在第一次进入页面时获取两次查询。我有一个类似的问题,查询是在父级和子级中获取的。

我认为您在 c) 中是对的,在调用 fetchMore 后它将重新呈现父级

于 2017-03-02T06:55:04.167 回答