【发布时间】:2017-07-21 01:22:20
【问题描述】:
我希望一个组件从其父组件接收其初始数据,同时仍然能够自行对数据进行分页。
例如,考虑
<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> 处理分页。这意味着我必须向 <StaticChild> 添加一个 shouldComponentUpdate 方法。
b) 让 <DynamicChild> 进行与 <Parent> 类似的初始查询,并依靠 Apollo 从 Redux 存储中提取第二个查询(假设这两个查询不会一起批处理)。
c) 让<Parent> 进行初始查询并将 fetchMore() 回调传递给<DynamicChild>。我担心当<DynamicChild> 使用回调时,它仍然会尝试重新渲染<Parent>。
虽然这些解决方案很简单,但有没有办法让<DynamicChild> 定义自己的分页查询而不定义自己的初始查询?
【问题讨论】:
标签: graphql react-apollo