Defjs
React

ClientProvider

Provide a Defjs client to React descendants via context.

@defjs/react · Function

Signature

function ClientProvider(props: ClientProviderProps): React.FunctionComponentElement<React.ProviderProps<DerivableClient | null>>;

Pass the client returned by createClient as client; descendants read it with useClient. The component does not create, cache, or dispose the client. A nested ClientProvider overrides the client for its own subtree, and a different client prop changes the context value for descendants.

Parameters

Prop

Type

client DerivableClient

Derivable client returned by createClient, owned by the application.

children? ReactNode

React tree that can call useClient.

Returns

A context provider element.

Examples

import { createClient, withEndpoint } from "@defjs/core";
import { ClientProvider } from "@defjs/react";
import type { ReactNode } from "react";

const client = createClient(withEndpoint("https://api.example.com"));

export function ApiProvider({ children }: { children: ReactNode }) {
  return <ClientProvider client={client}>{children}</ClientProvider>;
}
Edit this page on GitHub
Released under the MIT License. · Copyright © 2026 MunMunMiao