fix: stop flickering due to late initiated token

This commit is contained in:
Ali BARIN
2022-03-09 20:58:51 +01:00
parent 343b360303
commit 906a8d0644
4 changed files with 11 additions and 5 deletions

View File

@@ -2,7 +2,7 @@ import * as React from 'react';
import { ApolloProvider as BaseApolloProvider } from '@apollo/client';
import { useSnackbar } from 'notistack';
import client, { setLink } from 'graphql/client';
import { mutateAndGetClient } from 'graphql/client';
import useAuthentication from 'hooks/useAuthentication';
type ApolloProviderProps = {
@@ -17,9 +17,12 @@ const ApolloProvider = (props: ApolloProviderProps): React.ReactElement => {
enqueueSnackbar(message, { variant: 'error' });
}, [enqueueSnackbar]);
React.useEffect(() => {
setLink({ onError, token: authentication.token })
}, [onError, authentication]);
const client = React.useMemo(() => {
return mutateAndGetClient({
onError,
token: authentication.token,
});
}, [onError, authentication]);
return (
<BaseApolloProvider client={client} {...props} />