0
votes

I'm using React functional components with hooks and Apollo Client 3. I can use useLazyQuery to inspect the loading state in the component I'm using it in, but is it possible to inspect the loading state of that same query in a separate component using Apollo's own API, i.e. without passing props or using React's context?

1

1 Answers

0
votes

No. The state that's exposed through Apollo's hooks is specific to the component where the hook is called (it uses useRef under the hood). Even the data property, which may be populated by Apollo's in-memory cache and may be changed when the cache changes, is still just component state.

That said, you can call the same query across multiple components in your app and it will only be fetched once from your server provided you use the default fetchPolicy. That should be the case whether you're using useQuery or useLazyQuery.