You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP β†’
Socket
Book a DemoInstallSign in
Socket

react-client-async

Package Overview
Dependencies
Maintainers
0
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-client-async

React tools for async rendering in client side! πŸš€

1.3.7
latest
Source
npmnpm
Version published
Weekly downloads
31
1450%
Maintainers
0
Weekly downloads
Β 
Created
Source

βš›οΈβ³
React Async for Client

🎬 Demo Β· 🌟 GitHub Β· πŸ“¦ Package

πŸ‘‹ Introduction

This package helps you use async function without the need to migrate to βš›οΈ React 19 and server-side rendering!

  • ✨ Supports utility hooks to create and render async tasks.
  • ✨ Supports AbortSignal and automatic abort on re-render.

πŸš€ Install

npm i react-client-async

βœ… useAsync Hook

You can use the useAsync hook to create a task.

console.log(useAsync(promiseFn, args, options));

βœ… useAsyncMemo Hook

Use the useAsyncMemo hook to create a memoized async task.

const {
  load, stop,
  state: { result, pending, error }
} = useAsyncMemo(({ signal }) =>
      fetch("/package.json", { signal })
        .then((res) => res.json()),
  [ /* Function Dependencies */ ],
  { autoLoad: false, defaultResult: null },
);

βœ… Async Component

You can use the Async component to render an async component.

<Async
  $fc={fc} // may be an async function component
  $waiting={waiting} // waiting component
  $fallback={fallback} // fallback component
  {...props} // props for the function component
/>

🎬 Recursive Async Component Demo

Easy to wrap a recursive async component and memoize it.

const Rec: FC<{ n: number }> = wrap(
  async ({ [$signal]: signal, n }) =>
    // break the recursion
    (n <= 0) ? 0 : (
    // delay and recursion
      <>
        {await delay(99, signal)}
        {n} <Rec n={n - 1} /> {n}
      </>
    )
);

⏳ What is Next?

  • ⏳ useAsyncIterable hook
  • ⏳ AsyncIterable component
async function* IterableComponent() {
  yield* OtherIterableComponent();
  yield  await component1();
  yield  await component2();
  yield  <div>...</div>;
}

Looking forward to your feedback or contribution! πŸš€πŸš€πŸš€

Development

Install

  • Install bun runtime: npm install -g bun
  • Install dependencies: bun install

Run & Build

  • Run demo: bun dev
  • Build demo: bun build:app
  • Build package: bun build:lib

Deploy

  • Deploy demo to github pages: bun build:app:deploy
  • Publish this package to npm: bun build:lib:publish

Keywords

react

FAQs

Package last updated on 11 Mar 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts