Hey guys, I am using viewmodel in my compose appli...
# compose
v
Hey guys, I am using viewmodel in my compose application. I am calling api in my viewModel through
viewModelScope.launch
so when I call in my compose function, should I use any thing else? I am reading Side-effects using LunchEffect and DispoableEffect. Is this neccessary in my composable function? If yes can someone guide me, bcoz I unable to understand this concept. Thanks
Copy code
class MainActivityViewModel(private val resultRepository: ResultRepository) : ViewModel() {

    init {
        getSportResult()
    }

    fun getSportResult() {
        viewModelScope.launch {
            val response = resultRepository.getSportResult()
            
        }
    }
}
Copy code
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun SetupView(viewModel :MainActivityViewModel = koinViewModel()) {
    Scaffold(topBar = {
        TopAppBar(
            title = { Text(text = stringResource(id = R.string.app_name)) },
        )
    }, content = { padding ->
        Column(
            modifier = Modifier
                .fillMaxSize()
        ) {
            Button(onClick = { /*TODO*/ }) {
                Text(text = stringResource(id = R.string.get_result))
            }
        }
    })
}
Thanks guys..
z
Calling launch from an event handler is fine.
v
Ok that's great