saveState

inline fun <T : Any> SavedStateHandle.saveState(name: String = "", default: T? = null, json: Json = Json, serializer: KSerializer<T> = serializer<T>(), workerDispatcher: CoroutineDispatcher = Dispatchers.Default): StateDelegate<ViewModelState.Regular<T>>(source)

Creates plain saved state as a ViewModel property, for example val users by handle.saveState<List<User>>().

name defaults to the property name. default initializes only an absent saved entry. serializer and json encode the payload; complex models require a serializable type. The holder uses viewModelScope; access it on the main thread. Producers, transformations and codec preparation use workerDispatcher. Capture saved/UI inputs before starting an operation. Use ViewModelState.Regular.bind for flows or ViewModelState.set for direct values.