Suspense
wybthon.suspense¶
suspense
¶
Suspense component for rendering fallback UI during async loading.
Suspense subscribes to one or more
Resources and shows a fallback while any of
them are loading. Set keep_previous=True to keep showing the
previously-resolved children when refetching.
See Also
Functions:
| Name | Description |
|---|---|
Suspense |
Render a fallback while one or more resources are loading. |
Suspense
¶
Render a fallback while one or more resources are loading.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
props
|
Any
|
The component's props with the following keys:
|
required |
Returns:
| Type | Description |
|---|---|
Any
|
A reactive |
Any
|
between fallback and children. |
What's in this module¶
Suspense renders a fallback while any
create_resource in its subtree is pending.
It's the canonical way to coordinate loading states for async data and
lazy components.
Usage¶
from wybthon import Suspense, component, create_resource, create_signal
from wybthon.html import div, p, span
async def fetch_user(id_: int) -> dict:
...
@component
def UserCard(id):
user = create_resource(id, fetch_user)
return div(
p("Name: ", span(lambda: user()["name"])),
)
@component
def Profile():
id_, _ = create_signal(42)
return Suspense(
fallback=lambda: p("Loading…"),
children=lambda: UserCard(id=id_),
)
fallbackis a callable so it can stay reactive too.- The boundary waits for all pending resources in its subtree.