comlink-worker-pool-react
TypeScript icon, indicating that this package has built-in type declarations

0.0.2 • Public • Published

⚛️ comlink-worker-pool-react

npm version bun compatibleCI MIT License

🚀 Try the Live Playground Demo!

Effortless, scalable web worker pools for React.

Supercharge your React apps with parallelism and keep your UI buttery smooth. Powered by comlink-worker-pool — now with a beautiful, idiomatic hook-based API for React developers.


✨ Why comlink-worker-pool-react?

  • Blazing fast UI: Run CPU-intensive tasks in parallel, outside the main thread.
  • Zero boilerplate: Integrate worker pools with a single hook.
  • TypeScript first: Full type safety and autocompletion.
  • Seamless DX: Designed for React, by React devs.
  • Works using comlink-worker-pool underneath.

🚦 Features

  • 🪝 useWorkerPool() React hook for easy worker pool integration
  • 🧑‍💻 Simple, declarative API
  • 🛡️ TypeScript support out of the box
  • ⚡ Automatic pool management & lifecycle handling
  • 🔄 Real-time status, results, and error tracking
  • 🧩 Works with any Comlink-compatible worker

⚡ Quick Start

Install:

npm install comlink-worker-pool-react comlink-worker-pool

or

yarn add comlink-worker-pool-react comlink-worker-pool

Usage

  1. Create your worker (e.g., worker.ts)
// worker.ts
import { expose } from "comlink";

const api = {
  add: async (a: number, b: number) => a + b,
};

expose(api);
  1. Use the hook in your React component:
import { useWorkerPool } from "comlink-worker-pool-react";
import { wrap } from "comlink";

type Api = {
  add: (a: number, b: number) => Promise<number>;
};

const { api, status, result, error, call } = useWorkerPool<Api>({
  workerFactory: () => new Worker(new URL("./worker", import.meta.url)),
  proxyFactory: (worker) => wrap<Api>(worker),
  poolSize: 2,
});

return (
  <div>
    <button
      onClick={async () => {
        await call("add", 2, 3);
      }}
    >
      Add 2 + 3
    </button>
    {status}
    {result && <div>Result: {result}</div>}
    {error && <div>Error: {String(error)}</div>}
  </div>
);

💡 Tip: Try the live playground demo for a full working example!

Get Started Now!

Ready to make your React apps faster and smoother? Install comlink-worker-pool-react today and experience effortless parallelism.


Made with ❤️ by @natanelia

Dependents (0)

Package Sidebar

Install

npm i comlink-worker-pool-react

Weekly Downloads

15

Version

0.0.2

License

MIT

Unpacked Size

12.9 kB

Total Files

6

Last publish

Collaborators

  • natanelia