onInit

inline fun SavedStateHandle.onInit(key: String = DEFAULT_KEY, init: () -> Unit): SavedStateHandle

Executes the given init block if the state for key was NOT restored from process death.

This is useful for triggering initial data fetches or setup operations that should only happen on fresh launches. Ensure this is called after respawnMutableStateFlow.

Return

The SavedStateHandle for chaining.

Parameters

key

The state key to check.

init

The action to perform on fresh initialization.