All Downloads are FREE. Search and download functionalities are using the official Maven repository.

commonMain.com.adeo.kviewmodel.compose.ViewModel.kt Maven / Gradle / Ivy

package com.adeo.kviewmodel.compose

import androidx.compose.runtime.Composable
import androidx.compose.runtime.DisallowComposableCalls
import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.remember
import com.adeo.kviewmodel.KViewModel

@Composable
public fun  ViewModel(
    factory: @DisallowComposableCalls () -> T,
    content: @Composable (T) -> Unit
) {
    val viewModel = remember { factory() }
    content(viewModel)

    DisposableEffect(Unit) {
        onDispose(viewModel::clear)
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy