Suspensive

Packages to use React Suspense easily

README

Suspensive Libraries Logo


All declarative components to use suspense on both CSR, SSR.

Features


- Suspense, withSuspense (containing CSROnly)
- ErrorBoundary, withErrorBoundary, useErrorBoundary, useErrorBoundaryFallbackProps
- ErrorBoundaryGroup, withErrorBoundaryGroup, useErrorBoundaryGroup
- AsyncBoundary, withAsyncBoundary (containing CSROnly)
- Delay, withDelay
- SuspensiveProvider, Suspensive

Installation


  1. ```shell
  2. npm install @suspensive/react
  3. ```

  1. ```shell
  2. pnpm add @suspensive/react
  3. ```

  1. ```shell
  2. yarn add @suspensive/react
  3. ```

Usage


  1. ```tsx
  2. import { Suspense, ErrorBoundary, ErrorBoundaryGroup, Delay } from '@suspensive/react'

  3. const Example = () => (
  4.   <ErrorBoundaryGroup>
  5.     <ErrorBoundaryGroup.Reset trigger={(group) => <button onClick={group.reset}>Reset All</button>} />
  6.     <ErrorBoundary
  7.       fallback={(props) => (
  8.         <>
  9.           <button onClick={props.reset}>Try again</button>
  10.           {props.error.message}
  11.         </>
  12.       )}
  13.     >
  14.       <Suspense
  15.         fallback={
  16.           <Delay>
  17.             <Spinner />
  18.           </Delay>
  19.         }
  20.       >
  21.         <SuspendedComponent />
  22.       </Suspense>
  23.     </ErrorBoundary>
  24.   </ErrorBoundaryGroup>
  25. )
  26. ```





npm version
npm
npm bundle size

Declarative apis to use @tanstack/react-query with suspense easily.

Features


- useSuspenseQuery
- useSuspenseQueries
- useSuspenseInfiniteQuery
- QueryErrorBoundary, QueryAsyncBoundary

Installation


  1. ```shell
  2. npm install @suspensive/react-query
  3. ```

  1. ```shell
  2. pnpm add @suspensive/react-query
  3. ```

  1. ```shell
  2. yarn add @suspensive/react-query
  3. ```

Usage


  1. ```tsx
  2. import { Suspense } from '@suspensive/react'
  3. import { QueryErrorBoundary, useSuspenseQuery } from '@suspensive/react-query'

  4. const Example = () => (
  5.   <QueryErrorBoundary
  6.     fallback={(props) => (
  7.       <>
  8.         <button onClick={props.reset}>Try again</button>
  9.         {props.error.message}
  10.       </>
  11.     )}
  12.   >
  13.     <Suspense fallback={<Spinner />}>
  14.       <SuspendedComponent />
  15.     </Suspense>
  16.   </QueryErrorBoundary>
  17. )

  18. const SuspendedComponent = () => {
  19.   const query = useSuspenseQuery({
  20.     queryKey,
  21.     queryFn,
  22.   })

  23.   return <>{query.data}</>
  24. }
  25. ```



Docs


deployment

We provide Official Docs




Visualization

deployment

Concepts Visualization ready. You can see core concepts of Suspensive visually


Contributing


Read our Contributing Guide to familiarize yourself with Suspensive's development process, how to suggest bug fixes and improvements, and the steps for building and testing your changes.

Contributors


contributors

License


MIT © Suspensive. See LICENSE for details.

Suspensive Suspensive