React API
Every public export of @navios/di-react, with signatures. This page is for looking things up; the React guides explain how the pieces are used. Peer dependencies: @navios/di and react ^18.0.0 || ^19.0.0.
ContainerProvider
Every hook on this page throws when there is no ContainerProvider above it, with a message such as useContainer must be used within a ContainerProvider, except the scope hooks that return null or undefined.
ScopeProvider
Creates one ScopedContainer from the root container on mount and calls its dispose() on unmount. scopeId and metadata are read on mount only. Nested providers create independent scopes. Throws ScopeProvider must be used within a ContainerProvider without one. See Scopes and invalidation.
Service hooks
All three hooks share one set of overloads. Result stands for the hook's return type.
For a class decorated with @Factory, Instance is the type its create() returns. Calling a hook with a schema token and no arguments gives it the return type MissingArgsError<S> from @navios/di, a string literal naming the missing keys, so the first use of the result fails to compile.
Each hook resolves from the nearest ScopeProvider's scope, or from the root container when there is none, and resolves again when the instance is destroyed.
useService
args is compared by its JSON form; a new object with the same content does not restart the resolution. See Using services in components.
useSuspenseService
Returns the instance. Throws a promise while it is being resolved and the error when resolution fails, so it needs a Suspense boundary and an error boundary above it. Results are cached per container, token and JSON.stringify(args); a failure stays cached. See Suspense.
useOptionalService
The fields of UseServiceResult plus isNotFound. It is true, and error is undefined, when resolution fails because a provider is missing. Other failures are reported as in useService. See Optional services.
useInvalidateInstance
Returns a stable function that calls invalidate(instance) on the current container (the scope inside a ScopeProvider). The promise resolves when the instance and its dependents are destroyed. A value the container does not hold is ignored. See Invalidation.
Container hooks
Scope hooks
useScope returns the scope id. useScopeMetadata returns scope.getMetadata(key) cast to T, and undefined for a key that was not set. All of them read the innermost scope.
Contexts
The two contexts behind the providers and hooks. They are exported for code that has to read or supply them directly, for example a test helper; application code uses the providers.