rememberViewModel

@Composable
inline fun <VM : ViewModel> rememberViewModel(tag: String? = null): ViewModelLazy<VM>

Gets an instance of a VM as an android ViewModel for the given tag.

VM generic will be preserved!

Return

An instance of VM.

Parameters

VM

The type of the ViewModel to retrieve.

tag

The bound tag, if any. If changes during composition, a new instance will be created.

Throws

DI.NotFoundException

If no provider was found.

DI.DependencyLoopException

If the value construction triggered a dependency loop.


@Composable
inline fun <A : Any, VM : ViewModel> rememberViewModel(tag: String? = null, arg: A): ViewModelLazy<VM>

Gets an instance of a VM as an android ViewModel for the given tag.

VM generic will be preserved!

Return

An instance of VM.

Parameters

VM

The type of the ViewModel to retrieve.

tag

The bound tag, if any. If changed during composition, a new instance will be created.

A

The type of argument the returned factory takes.

arg

A function that returns the argument that will be given to the factory when curried. If changed during composition, a new instance will be created.

Throws

DI.NotFoundException

If no provider was found.

DI.DependencyLoopException

If the value construction triggered a dependency loop.