Apollo useQuery running only once and skipping when components re-rendered

Viewed 21

I am new to GraphQL and nextJS. In my current project, I want to fetch data only once from graphql server and use the same data all the time when components re-renders. I tried to use skip with useQuery hook but even the root component is rerendered so could not do it. I tried useLazyLoad and still no luck. Any leads would be highly appreciated. Thanks.

1 Answers

If I understand your question correctly. You could use a state for this. Load the data into the state. Because the data in the state does not change the method that retrieves the data wil not be called.

Related