saveResponseState

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

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

name defaults to the property name. default is a payload and initializes only an absent entry. serializer and json encode only the payload. Restored data becomes Success; errors and loading are transient. The holder uses viewModelScope; access it on the main thread. Worker callbacks and codecs use workerDispatcher and must not access the UI or handle. Each ViewModelState.Result.load replaces the preceding operation, while keeping the same state flow.