examples/preact/suspense
| Name | Last commit message | Last commit date |
|---|---|---|
| .. | ||
README.md
TanStack Preact Query Suspense Example#
Loads projects with suspense queries, and resets failed queries from an error boundary.
How it works#
src/services/projects/queries.tsdefinesprojectsQueries.list()andprojectsQueries.detail(id),queryOptionsfactories for TanStack repositories from the GitHub API.src/components/Projects.tsxandsrc/components/Project.tsxread their data withuseSuspenseQuery. Clicking "Load" starts the detail fetch withqueryClient.query(projectsQueries.detail(project.full_name))before switching views.src/index.tsxlazy-loads both components insideSuspense. Pressing "Show Projects" starts the list fetch withqueryClient.query(projectsQueries.list())while the component code is still loading.src/index.tsxalso wraps them inQueryErrorResetBoundary, whoseresetis passed asonResettosrc/components/ErrorBoundary.tsx, auseErrorBoundarywrapper. "Try again" resets the failed queries so they fetch again. TheQueryClientsetsretry: 0.
To run this example:
npm installnpm run dev