How to update props after this.props.client.query via 'withApollo' HOC ?
See original GitHub issueMy use case is that I do not want to do the initial query for search component, instead of that, I will trigger query after button click, seems like the only choice is withApollo HOC.
Here is my code fragment.
this.props.client.query({
query: doc,
variables: variant,
reducer: (previousResult, action, variables) => {
console.log('reducer!!!!!', previousResult, action, variables);
}
}).then((data) => {
console.log('then', data, this.props)
}).catch((err) => {
console.log('catch', err)
});
Fetching data is fine, I can get data in promise then, but how I can update it into props ? As the document http://dev.apollodata.com/core/apollo-client-api.html#ApolloClient\.query , reducer function should do that, but unfortenately it never be triggered in my sample code.
Did I do anything wrong? Or there is the other solution to solve that?
PS: version react-apollo@1.0.0-rc.2
Issue Analytics
- State:
- Created 6 years ago
- Reactions:9
- Comments:8 (1 by maintainers)
Top Results From Across the Web
HOC - Apollo GraphQL Docs
Use this function to create higher-order components that can execute queries and update reactively based on the data in your Apollo store. The...
Read more >How to update a separate components props after performing ...
I want to re-render Header when username changes. I'm not sure how to do this without polling the query. javascript · reactjs ·...
Read more >Dissecting React Apollo Render Props | by Marc G - Medium
Apollo comes with an HOC named withApollo which exposes the client object for our FakeQuery component to utilize via it's props and query...
Read more >React with Apollo and GraphQL Tutorial - Robin Wieruch
GraphQL Caching of Queries with Apollo Client in React ... It uses React's render props pattern, using a child as a function implementation ......
Read more >Tutorial: Render Props in React Apollo 2.1 - Prisma
Generally, the new render prop components Query, Mutation and ... started quickly with Apollo Client without much configuration overhead.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@smilexu Reducer is not the right choice for this. You should be able to use
client.writeQuery
orclient.writeFragment
to update the cache.Maybe a cleaner way to do this in React would be to have a Search component with a text field, then a searchResult component that’s nested inside it. The searchResult component gets the search text as a prop. That way you could directly attach the query to the searchResult component.
have you already tried to reset the store, after calling the “first” login/error
this.props.client.resetStore();
maybe it helps, its for me a kind of solution, but not in every case i have