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.