useResolver
useResolver returns the nearest module's Resolver - the read surface itself, rather than one instance out of it. Reach for it when a read is conditional, or happens in an event handler or a callback. What each method does on the kernel's own terms is on Container.
Signature
useResolver(): ResolverThe module's canonical resolver: the same object injectResolver() hands a service in that module, module.resolver exposes, and Resolver.for(container) returns.
Throws outside a boundary, with the message every module hook shares:
useModuleContext: no module in context. Wrap with <AppProvider> or <ModuleProvider>.import { useResolver } from "@remodulo/react"
function RefreshOrderButton() {
const resolver = useResolver()
// The nearest module's read surface, for a read that does not belong in render.
return (
<button type="button" onClick={() => void resolver.resolve(OrderStore).refresh()}>
Refresh
</button>
)
}RefreshOrderButton resolves OrderStore when the click happens, not when the component renders.
What is on it
| Method | Returns |
|---|---|
resolve(token, mode?) | The instance. Throws when nothing the mode can see registers the token. |
resolveOptional(token, mode?) | The instance, or undefined on a miss. |
resolveOr(token, fallback, mode?) | The instance, or the fallback - a value or a function. |
resolveAll(token, mode?) | Every member of a collection token; [] when nothing contributes. |
isRegistered(token, mode?) | true when a read would land. |
registrations() | A snapshot of every registration the module declares, in order. |
entry(token) | The snapshot of one token's registration; undefined when the module declares none. |
entries(token) | The snapshots of a multi token's contributions. |
on(event, listener) | The unsubscribe callback for the container's four events. |
Modes are a plain argument and match the hooks: "nearest" by default, "chained" on resolveAll.
There is no register
Bindings are declared when the module is built, never after. There is no fork or construct here either - both are container methods, and the React layer does not publish the container.