In this lesson we will first explore how to manually refetch data for an already executed query to receive the latest state of our data.
Later we use polling to refetch the latest state on a timed interval. Polling can be a simple and effective tool to provide an almost real-time experience without the overhead of setting up a WebSocket solution.
Great tutorial Nik! Render Props pattern seems interesting, but it doesn't seem to scale easily when multiple requests need to be made in the same component. How would you do that? Would HOC be more scalable and improve the code readability in this situation?
Hey @Tomás, some people indeed like the hoc more, but other struggle with it. I think eventually Apollo will be available using React Hooks and that, from my perspective will be a nice option.
@Nik, here you will find two solutions.
@Tomás, I'm scratching my head about this:
how come this works: <button onClick={() => refetch()}>Refetch</button>
and this doesn't: <button onClick={refetch}>Refetch</button>
Thank you @Nik Source code link is broken (on other lessons too). It should be https://github.com/nikgraf/graphql-apollo-client-course/tree/master/lesson-6.
@Sébastien cool, didn't know about this one. Thanks for the hint!
@chihab thanks, just informed someone from the Egghead team so they can fix it.
@Sébastien
I'd imagine it has to do with the fact that onClick
will pass an event
as the first parameter to the onClick function. Since I'm not sure about the signature of refetch()
, it may be that it is expecting a different argument as parameter 1. The best way to ensure that refetch()
is cleanly called and not passed anything weird by the browser's onClick semantics is to wrap it in a 0-arg function () => refetch()
.
Hi @Nik,
Great intro into Graph and Apollo, thanks for it. I would like to second @Alex's point, on updating this course for hooks. This would be super helpful as I believe hooks are the future for React.
I could not understand this with version 3 of apollo, could there be an update to this video?
I could not understand this with version 3 of apollo, could there be an update to this video?
Thanks! Unfortunately I don't have the time right now to do so :(
what a fantastic tutorial series! this is badass