Skip to Content
Wirebird Docs

WirebirdProvider

Holds the session, the API client and live updates for every Wirebird component below it.

import { WirebirdProvider } from '@wirebird/react';

<WirebirdProvider fetchToken={fetchToken}>{children}</WirebirdProvider>;

Mount it once, high in your tree. In a single-page app, put it above your router so the session, the live-update connection and any call in progress survive navigation. Every other Wirebird component must be inside it.

Props

PropTypeRequiredDescription
fetchToken() => Promise<{ token: string; expiresAt: string | Date }>YesCalls your session endpoint. Called on mount, five minutes before expiry and on a 401.
tokenstringNoA token you already minted (for example, server-rendered into the page). Saves the first fetchToken call.
expiresAtstring | DateWith tokenWhen token expires.
themePartial<WirebirdTheme>NoColours, font, radius and density. See Theming.
apiBaseUrlstringNoDefaults to https://api.getwirebird.com (exported as DEFAULT_API_BASE_URL). Only change it for testing environments we give you.

fetchToken can be a new function on every render; the provider always uses the latest one without reconnecting.

One business per provider

A provider's session is for one business and one user. If a user switches business in your app, give the provider a key so it starts a fresh session:

<WirebirdProvider key={currentCompanyId} fetchToken={fetchToken}>
  {children}
</WirebirdProvider>

On this page