Hello Everyone, I am stuck in a problem in jetpack...
# android
a
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
n
Use
LaunchedEffect(viewModel) { viewModel.doStuff() }
.
a
Thanks a lot @natario1, That helped 👍