I used to fire a query like:
const { loading, error, data } = useQuery(GET_DOGS, {
fetchPolicy: 'cache-and-network', // Doesn't check cache before making a network request
});
and later in the code do something like:
loading ? <Loader> : data.map...
Does this pattern actually make app behave as if I used fetchPolicy: ‘network-only’?
If I understand the docs correctly what happens is:
- Apollo makes the call anyway
- It checks whether data is available in the cache and if so it returns cached data.
- When HTTP call is finished data is updated with what’s been returned and so is cache
If this reasoning is correct, to make use of cache I should do something in a fashion of:
!data && loading && <Loader>
data ? data.map... : null
I would love to get second opinion on that, as it would mean dramatic performance differences for my app.