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
| Prop | Type | Required | Description |
|---|---|---|---|
fetchToken | () => Promise<{ token: string; expiresAt: string | Date }> | Yes | Calls your session endpoint. Called on mount, five minutes before expiry and on a 401. |
token | string | No | A token you already minted (for example, server-rendered into the page). Saves the first fetchToken call. |
expiresAt | string | Date | With token | When token expires. |
theme | Partial<WirebirdTheme> | No | Colours, font, radius and density. See Theming. |
apiBaseUrl | string | No | Defaults 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>