Reputation: 2185
I have a MutableState
-- how to create a callback that will be called each time its value changes in a non-Composable function?
Upvotes: 1
Views: 637
Reputation: 66674
I think SnapshotFlow is what you might need. It also lets you filter, map use any Flow operator that you might need too.
val stateQuery by remember { mutableStateOf("") }
LaunchedEffect(Unit) {
snapshotFlow {
stateQuery
}
.distinctUntilChanged()
.onEach { query ->
viewModel.search(query)
}
.launchIn(this)
}
Upvotes: 2