私はこれについて間違った方法をとっていることに気付きました。私はこの役に立つポストを見つけました: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を使用します反応したネイティブを使用して)。
私は実際にそうしたいと思ったら私の店を更新する方法を知った。コンポーネントは、このためにreact-apollo
から仕事に両方graphql
とwithApollo
高次成分によってラップされる必要があります:
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)
});
それはほとんどの状態を更新するようなものです還元還元剤中に存在する。