Skip to content

DropInProvider

function DropInProvider(props): Element;

Provides a DropInClient (and its per-feed cache) to the hooks below.

Accepts either form:

  • <DropInProvider client={myClient}> — bring your own, already-constructed client.
  • <DropInProvider apiKey={k} url={u} tokenProvider={fn}> — the provider builds the client for you. tokenProvider is called lazily, only when a request needs a token.

Both forms accept enabled (default true). enabled={false} puts the whole tree into an inert mode: NO client is constructed, zero network requests are ever made, and every hook returns its normal shape with empty data, isLoading: false, error: null and enabled: false. Action functions become no-ops that RESOLVE to undefined — not rejections — so an optional feed integration (<DropInProvider enabled={!!apiKey}>) can never break the host app’s flow. Check useDropInEnabled() (or the enabled field on any hook return) when the app needs to know. Note: rendering hooks with no provider at all still throws — disabled mode is an explicit choice, missing configuration stays loud.

Both forms also accept an optional onError (typed OptimisticOnError) that every hook’s optimistic action uses as the default error sink — see “Optimistic-write error handling” in the README.

Note: the client is memoized on apiKey/url/userId, never on tokenProvider — that is an inline arrow in most apps, and keying on it would rebuild the client every render. Pass userId whenever the signed-in user can change without remounting this provider. Without it the memo holds the old client, which holds a still-valid token for the previous user, and the next user reads that user’s feed. A provider that is remounted on sign-in, or whose tokenProvider always mints for one session, needs nothing.

Parameter Type
props ProviderProps

Element