Reference

FanbaseProvider

Props, session adapter, query client behaviour.

Configuration, session and API client for everything below it. Mount near the root.

Props

PropRequiredWhat it is
tenantyesTenant host. Sent as xb-tenant on every request.
slugyesCommunity slug.
appIdyesIdentifier for this app or environment.
httpOptionsyes{ gamerBaseUrl, locale }.
sessionyesAdapter with get, set, clear.
queryClientyesYour QueryClient. You own it.
childrenyesYour tree.

httpOptions

KeyNotes
gamerBaseUrlAPI base URL. Differs between beta and production.
localeLanguage for API-side content. Defaults to en.

session

interface SessionAdapter {
  get(): Session | null
  set(session: Session): void
  clear(): void
}

localStorage is fine for a browser SPA. Swap for cookies or a server-backed store without touching anything else.

Query client

The provider mounts its own QueryClientProvider around your children, using the client you passed. Your useQuery calls need to be inside it, which they are if the provider is near the root.

Example

<FanbaseProvider
  tenant={import.meta.env.VITE_FANBASE_TENANT}
  slug={import.meta.env.VITE_FANBASE_COMMUNITY_SLUG}
  appId={import.meta.env.VITE_FANBASE_APP_ID}
  httpOptions={{
    gamerBaseUrl: import.meta.env.VITE_FANBASE_GAMER_BASE_URL,
    locale: 'en',
  }}
  session={sessionAdapter}
  queryClient={queryClient}
>
  <App />
</FanbaseProvider>

Mounting

One provider per app. Nesting is not supported and multiple providers do not give you multiple communities in one tree.

Wait for state.ready from useFanbase() before acting on session state anywhere below.

On this page