Use useLazyQuery to manually execute a query with Apollo React Hooks

Share this video with your friends

Send Tweet

When using useQuery from Apollo React Hooks, the request will be sent automatically after the component has been mounted. This might not be the desired behaviour as we might want to send the request in response to user action (for instance, after a button click).

In this lesson we're going to learn how to use useLazyQuery hook to execute a query manually in order to fetch dog pictures.

Liam
Liam
~ 5 years ago

Is there anyway to reset the useLazyQuery query and data? I have a search box that uses useLazyQuery. When I select a result, I want the data and called variables exposed in useLazyQuery to reset, but still have the exposed function (doQuery or getDog in this case) available in the component to use again if the user searches for a new term.