I want to call my ViewModel's function every 5 seconds. What is the best way to do that in Jetpack Compose?
I want to call my ViewModel's function every 5 seconds. What is the best way to do that in Jetpack Compose?
It depends when you want this behaviour to start and end.
This will run as long as your composable remains in the composition:
LaunchedEffect(Unit) {
while(true) {
vm.someMethod()
delay(5000)
}
}