Suspense
fun Suspense(fallback: @Composable BoxScope.() -> Unit, modifier: Modifier = Modifier, state: SuspenseState = remember { SuspenseState() }, contentThreshold: Duration = 3.seconds, content: @Composable () -> Unit)
Suspense render a fallback UI while some asynchronous work is being done.
Typically, this function is defined at least once at the top level of a screen and used for initial loading. Suspense can be nested as needed, which is useful for performing partial loading.
Usage:
Suspense(
fallback = { ContentLoading(modifier = Modifier.matchParentSize()) },
modifier = Modifier.fillMaxSize()
) {
val query = rememberGetPostsQuery()
Await(query) { posts ->
PostList(posts)
}
}
Content copied to clipboard
Parameters
fallback
The fallback UI to render components like loading.
modifier
The modifier to be applied to the layout.
state
The SuspenseState to manage the suspense.
contentThreshold
The duration after which the initial content load is considered complete.
content
The content to display when the suspense is not awaited.