Is there a way to directly react to changes from a "State" like e.g. the DatePickerState? I would want something like a onDateSelect lambda for simplicity
a
Alexander Zhirkevich
04/04/2024, 9:45 AM
Copy code
val state = rememberDatePickerState()
LaunchedEffect(state, onDateSelected){
snapshotFlow {
state.selectedDateMillis
}.collect { millis ->
onDateSelected(millis)
}
}
m
Marc
04/04/2024, 10:01 AM
Thanks!
z
Zach Klippenstein (he/him) [MOD]
04/04/2024, 3:25 PM
One tweak to that would be to put your onDateSelected lambda in something like a rememberUpdatedState so you don’t have to restart the effect if a different callback is passed (which will fire that callback immediately for the current value) - unless that’s the behavior you want.