Archie
08/09/2024, 9:40 AM@Composable
fun doSomething(): State<String> {
val (state, setState) = remember { mutableStateOf("") }
...
// do something with state like for example
setState("Helo")
...
return state
}
Archie
08/09/2024, 9:44 AM@Composable
fun CallSite() {
val state by doSomething()
Text(state)
}
Is this okay?Archie
08/09/2024, 9:47 AM@Composable
fun doSomething(onStateChange: (String) -> Unit) {
...
// do something with state like for example
onStateChange("Helo")
...
}
and so I’d be calling the it like this:
@Composable
fun CallSite() {
var state by remember { mutableStateOf("") }
doSomething { state = it }
Text(state)
}
But I feel like the first approach is cleaner? Thoughts?stantronic
08/09/2024, 11:43 AMstantronic
08/09/2024, 11:50 AMstantronic
08/09/2024, 11:52 AMChrimaeon
08/09/2024, 11:56 AMChrimaeon
08/09/2024, 11:59 AMState
.Archie
08/09/2024, 12:01 PMChrimaeon
08/09/2024, 12:03 PMArchie
08/09/2024, 12:04 PMChrimaeon
08/09/2024, 12:06 PMStylianos Gakis
08/09/2024, 12:09 PMStylianos Gakis
08/09/2024, 12:10 PMArchie
08/09/2024, 12:11 PM@Composable
fun Something(): State<...> {
fun Something(): State<...> {
val state = remember { mutableStateOf() }
LaunchedEffect {
LibraryCallThatOutputMultiplrValuesOvertime
LibraryCallThatOutputMultiplrValuesOvertime
.addListener { state.value = it }
}
}
return state
}
So in this case I just want to display the value being outputed by the library.Stylianos Gakis
08/09/2024, 12:12 PMArchie
08/09/2024, 12:12 PMChrimaeon
08/09/2024, 12:13 PMArchie
08/09/2024, 12:15 PMStylianos Gakis
08/09/2024, 12:15 PMStylianos Gakis
08/09/2024, 12:16 PMArchie
08/09/2024, 12:17 PMArchie
08/09/2024, 12:19 PMArchie
08/09/2024, 12:20 PM