albertosh
03/16/2021, 5:34 PMsuspend fun fetchContent(): String {
println("Loading...")
delay(2000)
println("Done!")
return "Hello world from suspend"
}
fun main() = Window {
val coroutineScope = rememberCoroutineScope()
var (content, setContent) = remember { mutableStateOf("Loading...") }
coroutineScope.launch {
setContent(fetchContent())
}
Text(content)
}
Which not only looks ugly as hell, it’s also invoking fetchContent twice (I can see it in stdout)Sebastian Aigner
03/16/2021, 5:46 PMalbertosh
03/16/2021, 5:48 PMZach Klippenstein (he/him) [MOD]
03/16/2021, 6:14 PMproduceState
if you’re using a LaunchedEffect
to update a MutableState