You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
import{WatchQueryFetchPolicy}from"@apollo/client";import{useHydrated}from"./useHydrated";exporttypeUseFetchPoliciesAfterHydrationParams={afterHydrationFetchPolicy?: WatchQueryFetchPolicy;afterHydrationNextFetchPolicy?: WatchQueryFetchPolicy;beforeHydrationFetchPolicy?: WatchQueryFetchPolicy;beforeHydrationNextFetchPolicy?: WatchQueryFetchPolicy;};/** * useFetchPoliciesAfterHydration * * To get around an issue with SSR/Apollo showing the incorrect loading status * we're going to load the initial request with cache-first and then * swap out the fetchPolicy so that the loading indicator is not incorrectly shown * while reading from the apollo cache * https://github.com/apollographql/apollo-client/issues/8669 * * */exportfunctionuseFetchPoliciesAfterHydration({
afterHydrationFetchPolicy ="cache-and-network",
afterHydrationNextFetchPolicy,
beforeHydrationFetchPolicy ="cache-first",
beforeHydrationNextFetchPolicy ="cache-first",}: UseFetchPoliciesAfterHydrationParams={}){constisHydrated=useHydrated();returnisHydrated
? {fetchPolicy: afterHydrationFetchPolicy,nextFetchPolicy: afterHydrationNextFetchPolicy??beforeHydrationNextFetchPolicy,}
: {fetchPolicy: beforeHydrationFetchPolicy,nextFetchPolicy: beforeHydrationNextFetchPolicy};}
The text was updated successfully, but these errors were encountered:
mariusc23
changed the title
Add useFetchPolicyAfterHydrationHook
Add useFetchPolicyAfterHydration hook
Jan 25, 2023
Change the fetch policy from
cache-first
tocache-and-network
on mount to fix apollographql/apollo-client#8669The text was updated successfully, but these errors were encountered: