Documents
context
context
Type
External
Status
Published
Created
Mar 17, 2026
Updated
Mar 17, 2026
Source
View
The context API is experimental and not yet stable. It may change significantly in a future version.

Context lets you pass values through the resource tree without threading props through every level — the same idea as React's createContext / useContext.

createResourceContext#

Create a context with a default value.

import { createResourceContext } from "@assistant-ui/tap";

const ThemeContext = createResourceContext("light");

Reading context#

Read the current value of a context inside a resource with tap.

import { tap } from "@assistant-ui/tap";

const Button = resource(() => {
  const theme = tap(ThemeContext);
  // ...
});

withContextProvider#

Provide a context value to all resources rendered within the callback.

import { withContextProvider } from "@assistant-ui/tap";

const App = resource(() => {
  const child = withContextProvider(ThemeContext, "dark", () => {
    return tapResource(Button());
  });

  return child;
});

Any resource rendered inside the callback — including deeply nested children — will read "dark" from ThemeContext.

Context is not properly persisted across `tapResourceRoot` boundaries. If a child resource is wrapped with `tapResourceRoot`, it may not see context values provided by its ancestors. This is a known bug.