Skip to content

Commit

Permalink
Reduce import bundle size
Browse files Browse the repository at this point in the history
  • Loading branch information
rubendinho committed Dec 14, 2024
1 parent d77e879 commit 3a999bf
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions packages/react/src/providers/QuilttAuthProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use client'

import type { FC, PropsWithChildren } from 'react'
import { useEffect } from 'react'
import { useEffect, useMemo } from 'react'

import { ApolloProvider } from '@apollo/client'
import { InMemoryCache, QuilttClient } from '@quiltt/core'
Expand All @@ -12,10 +12,6 @@ type QuilttAuthProviderProps = PropsWithChildren & {
token?: string
}

export const GraphQLClient = new QuilttClient({
cache: new InMemoryCache(),
})

/**
* If a token is provided, will validate the token against the api and then import
* it into trusted storage. While this process is happening, the component is put
Expand All @@ -26,6 +22,15 @@ export const GraphQLClient = new QuilttClient({
export const QuilttAuthProvider: FC<QuilttAuthProviderProps> = ({ token, children }) => {
const { session, importSession } = useQuilttSession()

// @todo: extract into a provider so it can accessed by child components
const GraphQLClient = useMemo(
() =>
new QuilttClient({
cache: new InMemoryCache(),
}),
[]
)

// Import passed in token
useEffect(() => {
if (token) importSession(token)
Expand Down

0 comments on commit 3a999bf

Please sign in to comment.