【发布时间】:2019-01-15 04:06:49
【问题描述】:
假设我有一个带有查询的组件:
<Query query={GET_THING}>
{({ loading, error, data, refetch }) => {
if (loading) return <Text>Loading...</Text>;
if (error) return <Text>Error :(</Text>;
// currently am just storing refetch in global var
globalRefetches.thing = refetch;
// external component can call globalRefetches.thing()
return <Text>{data.getThing}</Text>;
}}
/>
然后我导航到过滤器屏幕,我可以在其中设置一些过滤器来调整结果。
- 这个屏幕不是前一个组件的子屏幕,所以我不能简单地通过 props 传递 refetch。
- 按“保存过滤器”不是突变(它不会访问服务器并更改数据库,而只是更改传递给上一个查询的局部变量),所以我没有 refetchQueries。李>
我有没有一种干净的方法来重新获取上一个屏幕上的查询?目前,我只是将它们存储在全局变量中,但我想有一些方法可以将查询从存储中拉出并使用新变量重新获取它?
【问题讨论】:
标签: react-apollo apollo-client apollostack