Hey guys, any way to use collectAsStateWithLifecyc...
# multiplatform
q
Hey guys, any way to use collectAsStateWithLifecycle on Compose Multiplatform?
e
it's available only for Android, so using expect-actual pattern can help: Shared:
Copy code
@Composable
expect fun <T> StateFlow<T>.collectAsStateMultiplatform(
    context: CoroutineContext = EmptyCoroutineContext,
): State<T>
Android:
Copy code
@Composable
actual fun <T> StateFlow<T>.collectAsStateMultiplatform(
    context: CoroutineContext,
): State<T> = collectAsStateWithLifecycle(context = context)
iOS:
Copy code
@Composable
actual fun <T> StateFlow<T>.collectAsStateMultiplatform(
    context: CoroutineContext,
): State<T> = collectAsState(context)
853 Views