import asyncio
import solara
from solara.lab import task
@task
async def fetch_data():
await asyncio.sleep(2)
return "The answer is 42"
@solara.component
def Page():
solara.Button("Fetch data", on_click=fetch_data)
solara.ProgressLinear(fetch_data.pending)
if fetch_data.finished:
solara.Text(fetch_data.value)
elif fetch_data.not_called:
solara.Text("Click the button to fetch data")
# Optional state check
# elif fetch_data.cancelled:
# solara.Text("Cancelled the fetch")
# elif fetch_data.error:
# solara.Error(str(fetch_data.exception))