only render fragment data when component is mounted: Apollo Client

173 Views Asked by At

I was using Relay Modern and now I am using Apollo Client. I would like to write the equivalent of a fragment component.

In Relay Modern, the fragment data is only available in the component that requires it and it is only fetched when the component is mounted. Is it possible to have the same behaviour in Apollo Client?

In my example the Child's data is available in the parent and it is fetched before the component is mounted.

Question:

can I set up apollo client the child fragment data is only fetched when the child mounts

1

There are 1 best solutions below

1
szaman On

If I understand correctly what you're asking for, I believe this will be possible using a useFragment hook. This is currently under development and you can track the progress in this github issue.

As of right now, I think you need to find a workaround, such as using two separate queries for fetching the parent and child data.