import { ErrorBoundary, Match, Suspense, Switch, children } from 'solid-js' import type { UseQueryResult } from '@tanstack/solid-query' import type { JSX } from 'solid-js' export interface QueryBoundaryProps { query: UseQueryResult /** * Triggered when the data is initially loading. */ loadingFallback?: JSX.Element /** * Triggered when fetching is complete, but the returned data was falsey. */ notFoundFallback?: JSX.Element /** * Triggered when the query results in an error. */ errorFallback?: (err: Error, retry: () => void) => JSX.Element /** * Triggered when fetching is complete, and the returned data is not falsey. */ children: (data: Exclude) => JSX.Element } /** * Convenience wrapper that handles suspense and errors for queries. Makes the results of query.data available to * children (as a render prop) in a type-safe way. */ export function QueryBoundary(props: QueryBoundaryProps) { return ( props.errorFallback ? ( props.errorFallback(err, async () => { await props.query.refetch() reset() }) ) : (
{err.message}
) } > {/* {props.errorFallback ? ( props.errorFallback ) : (
{props.query.error?.message}
)}
*/} {props.notFoundFallback ? ( props.notFoundFallback ) : (
not found
)}
{props.children( props.query.data as Exclude, )}
) }