Reference
FanbaseProvider
Props, session adapter, query client behaviour.
Configuration, session and API client for everything below it. Mount near the root.
Props
| Prop | Required | What it is |
|---|---|---|
tenant | yes | Tenant host. Sent as xb-tenant on every request. |
slug | yes | Community slug. |
appId | yes | Identifier for this app or environment. |
httpOptions | yes | { gamerBaseUrl, locale }. |
session | yes | Adapter with get, set, clear. |
queryClient | yes | Your QueryClient. You own it. |
children | yes | Your tree. |
httpOptions
| Key | Notes |
|---|---|
gamerBaseUrl | API base URL. Differs between beta and production. |
locale | Language 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.