useModel<
TConfig,TModel>(createModel,config):object
Defined in: hooks/useModel.ts:23
React hook to instantiate and manage a model or task instance with automatic lifetime management.
It manages the lifecycle of a model or task runner instance. When the configuration changes or the component unmounts, it automatically disposes of the previous instance to prevent native memory leaks.
TConfig
The configuration type passed to the model creator.
TModel extends object
The type of the compiled model instance containing a
dispose method.
(config) => Promise<TModel>
An asynchronous factory function to instantiate the model or task runner.
The configuration to pass to createModel, or undefined if
the model shouldn't be loaded yet. It is tracked by value, so the model is
re-created whenever the config's contents change and passing an inline object
is safe.
TConfig | undefined
object
An object containing the loaded model instance and any instantiation error.
error:
Error|undefined
model:
TModel|undefined