onActiveValueChange

inline fun <S : ModuleState, T> onActiveValueChange(crossinline selector: (S) -> T, crossinline onChange: suspend (T) -> Unit)(source)

Watches a selected value from state and triggers a callback when it changes.

Use this for side effects like analytics tracking or navigation that should happen in response to state changes while the composable is active.

Example:

@Composable
fun AnalyticsTracker() {
onActiveValueChange<NavigationState, String>(
selector = { it.currentEntry.navigatable.route }
) { route ->
analytics.trackScreenView(route)
}
}

Parameters

selector

Function to extract the value to watch from the state

onChange

Callback invoked when the selected value changes