所以我意識到我正在走這個錯誤的路。我發現這個有用的帖子:search feature with react-apollo。
我會更簡單有狀態,然後更新所述狀態,象這樣的迴應:
this.props.client.query({
query: MY_QUERY,
variables: {
first, // for pagination
skip,
orderBy,
searchText
},
}).then(result => this.setState({ thingsToRender: result.data.thingsToRender });
那麼你當然會呈現由映射對象在它或使用FlatList(如果你使用反應原生)。
我也發現如何更新我的店面,如果我真的想這樣做。該組件將需要由雙方graphql
和withApollo
高階組件從react-apollo
包裹這個工作:
compose(
withApollo,
graphql(SOME_QUERY)
)(MyComponent)
你再做出這樣的方法使:
onSearchButtonPress = async() => {
const { first, skip, orderBy, searchText } = this.state;
const result = await this.props.client.query({
query: MY_QUERY,
variables: {
first,
skip,
orderBy,
searchText
}
});
const items = result.data.items;
this.props.data.updateQuery(prev => ({
...prev,
allItems: _.uniqBy([...prev.allItems, ...items], o => o.id)
// lodash uniqBy helper method helps with removing older items
// with the same id (essentially updating them)
});
這幾乎就像更新狀態在減速機中。