ditox-react
Binds the module to a new dependency container.
If a parent container is exist, it is connected to the current one by default. Functions
Provides a new dependency container to React app
This component creates a new container and provides it down to React children.
If `binder` callback is specified, it will be called for a new container to binds it with dependencies.
If a parent container is exist, it is connected to the current one by default. For making a new root container specify `root` parameter as `true`, and the container will not depend on any parent container. Functions
Returns a dependency by token, or `undefined` in case the dependency is not provided. Functions
Returns a dependency by token, or fails with an error. Functions
Returns a dependency container, or `undefined` in case the container is not provided. Functions
Returns a dependency container. Throws an error in case the container is not provided. Functions
Ƭ DependencyContainerBinder: (container
: Container
) => unknown
▸ (container
): unknown
A callback for binding dependencies to a container
Name | Type |
---|---|
container |
Container |
unknown
Ƭ DependencyContainerParams: Object
Specifies an existed container or options for a new container:
Property
A callback which setup bindings to the container.
Property
If true
then a new container does not depend on any parent containers
Name | Type |
---|---|
binder? |
DependencyContainerBinder |
children |
ReactNode |
root? |
boolean |
Binds the module to a new dependency container.
If a parent container is exist, it is connected to the current one by default. Functions
▸ DependencyModule(params
): ReactElement
Example
const LOGGER_MODULE: ModuleDeclaration<LoggerModule> = {
function App() {
return (
<DependencyModule module={LOGGER_MODULE}>
<NestedComponent />
</DependencyModule>
);
}
Name | Type | Description |
---|---|---|
params |
Object |
- |
params.children |
ReactNode |
- |
params.module |
ModuleDeclaration <Module <Record <string , unknown >>> |
Module declaration for binding |
params.scope? |
"scoped" | "singleton" |
Optional scope for binding: singleton (default) or scoped . |
ReactElement
Provides a new dependency container to React app
This component creates a new container and provides it down to React children.
If `binder` callback is specified, it will be called for a new container to binds it with dependencies.
If a parent container is exist, it is connected to the current one by default. For making a new root container specify `root` parameter as `true`, and the container will not depend on any parent container. Functions
▸ DependencyContainer(params
): ReactElement
Example
const TOKEN = token();
function appDependencyBinder(container: Container) {
container.bindValue(TOKEN, 'value');
}
function App() {
return (
<DependencyContainer root binder={appDependencyBinder}>
<NestedComponent />
</DependencyContainer>
);
}
Name | Type |
---|---|
params |
DependencyContainerParams |
ReactElement
Returns a dependency by token, or `undefined` in case the dependency is not provided. Functions
▸ useOptionalDependency<T
>(token
): T
| undefined
Name |
---|
T |
Name | Type |
---|---|
token |
Token <T > |
T
| undefined
Returns a dependency by token, or fails with an error. Functions
▸ useDependency<T
>(token
): T
Name |
---|
T |
Name | Type |
---|---|
token |
Token <T > |
T
Returns a dependency container, or `undefined` in case the container is not provided. Functions
▸ useDependencyContainer(mode
): Container
Name | Type |
---|---|
mode |
"strict" |
Container
▸ useDependencyContainer(mode?
): Container
| undefined
Name | Type |
---|---|
mode? |
"optional" |
Container
| undefined
Returns a dependency container. Throws an error in case the container is not provided. Functions
▸ useDependencyContainer(mode
): Container
Name | Type |
---|---|
mode |
"strict" |
Container
▸ useDependencyContainer(mode?
): Container
| undefined
Name | Type |
---|---|
mode? |
"optional" |
Container
| undefined