Shivam Dhuria
03/18/2022, 9:05 PMdebounce
on a flow from within a Composable. I get this warning
Flow operator functions should not be invoked within composition . I am not using Viewmodels so can’t run the flow operator in the VM. Ideally I’d just want to call debounce
on the fullNameFlow
and trigger some changes in the composable. What’s the best way to go forward?
//This is inside a Composable
val fullNameFlow = MutableStateFlow("")
fullNameFlow.debounce(3000).mapLatest {
Log.i(TAG,it)
//Change Composable State
}
FormTextField(
onValueChange = {
fullNameFlow.value = it
}
)
Patrick Kellison
03/19/2022, 12:50 AM@Composable
fun Form(onUpdate: (String) -> Unit){
FormTextField(){ latest ->
onUpdate(latest)
}
}
Zach Klippenstein (he/him) [MOD]
03/20/2022, 4:53 PMZach Klippenstein (he/him) [MOD]
03/20/2022, 4:56 PMval fullNameFlow = remember { MutableStateFlow(“”) }
LaunchedEffect(fullNameFlow) {
// Don't need to remember here because the launched effect lives across recompositions.
fullNameFlow
.debounce(3000)
.mapLatest { … }
.collect { … }
}
Shivam Dhuria
03/22/2022, 7:04 PMShivam Dhuria
03/22/2022, 7:04 PM