Hello Everyone, I am stuck in a problem in jetpack compose. How can I launch a suspend function in my viewmodel from a @Composable function as soon as the screen is Loaded?
Solutions I have Tried:
Copy code
@Composable
fun FollowInterestsContent(actions: MainActions,viewModel:UserOnboardViewModel){
val coroutinesScope = rememberCoroutineScope()
viewModel.setInterestsList(context)
}
This ReturnsĀ
Suspend function 'setInterestsList' should be called only from a coroutine or another suspend function
Next I tried is
Copy code
@Composable
fun FollowInterestsContent(actions: MainActions,viewModel:UserOnboardViewModel){
val coroutinesScope = rememberCoroutineScope()
coroutinesScope.launch { viewModel.setInterestsList(context) }
}
This ReturnsĀ
Calls to launch should happen inside a LaunchedEffect and not composition