ComputeKit Logo

ComputeKit

The React-first toolkit for WASM and Web Workers

Run heavy computations with React hooks. Use WASM for native-speed performance. Keep your UI at 60fps.

Get Started View on GitHub


✨ Features

FeatureDescription
βš›οΈ React-firstPurpose-built hooks like useCompute with loading, error, and progress states
πŸ¦€ WASM integrationLoad and call AssemblyScript/Rust WASM modules with zero boilerplate
πŸš€ Non-blockingEverything runs in Web Workers, keeping your UI at 60fps
πŸ”§ Zero configNo manual worker files, postMessage handlers, or WASM glue code
πŸ“¦ TinyCore library is ~3KB gzipped
🎯 TypeScriptFull type safety for your compute functions and WASM bindings
πŸ”„ Worker poolAutomatic load balancing across CPU cores
πŸ“Š Progress trackingBuilt-in progress reporting for long-running tasks
πŸ”— Multi-stage pipelinesChain compute operations with usePipeline for complex workflows

πŸ€” Why ComputeKit?

You can use Web Workers and WASM without a library. But here’s the reality:

TaskWithout ComputeKitWith ComputeKit
Web Worker setupCreate separate .js files, handle postMessage, manage callbackskit.register('fn', myFunc)
WASM loadingFetch, instantiate, memory management, glue codeawait loadWasmModule('/my.wasm')
React integrationManual state, effects, cleanup, abort handlinguseCompute() hook
Worker poolingBuild your own pool, queue, and load balancerBuilt-in
Multi-stage workflowsManual chaining, error handling per stage, retry logicusePipeline() hook
TypeScriptTricky worker typing, no WASM typesFull type inference
Error handlingTry-catch across message boundariesAutomatic with React error states

ComputeKit’s unique value: The only library that combines React hooks + WASM + Worker pool into one cohesive, type-safe developer experience.


🎯 When to use ComputeKit

βœ… Use ComputeKit❌ Don’t use ComputeKit
Image/video processingSimple DOM updates
Data transformations (100K+ items)Small array operations
Mathematical computationsAPI calls (use native fetch)
Parsing large filesString formatting
Cryptographic operationsUI state management
Real-time data analysisSmall form validations
Multi-file processing pipelinesSimple single-step tasks

πŸ“¦ Installation

# npm
npm install @computekit/core

# With React bindings
npm install @computekit/core @computekit/react

# pnpm
pnpm add @computekit/core @computekit/react

# yarn
yarn add @computekit/core @computekit/react

Getting Started

Basic Usage (Vanilla JS)

import { ComputeKit } from '@computekit/core';

// 1. Create a ComputeKit instance
const kit = new ComputeKit();

// 2. Register a compute function
kit.register('fibonacci', (n: number) => {
  if (n <= 1) return n;
  let a = 0,
    b = 1;
  for (let i = 2; i <= n; i++) {
    [a, b] = [b, a + b];
  }
  return b;
});

// 3. Run it (non-blocking!)
const result = await kit.run('fibonacci', 50);
console.log(result); // 12586269025 β€” UI never froze!

React Usage

import { ComputeKitProvider, useComputeKit, useCompute } from '@computekit/react';
import { useEffect } from 'react';

// 1. Wrap your app with the provider
function App() {
  return (
    <ComputeKitProvider>
      <AppContent />
    </ComputeKitProvider>
  );
}

// 2. Register functions at the app level
function AppContent() {
  const kit = useComputeKit();

  useEffect(() => {
    kit.register('fibonacci', (n: number) => {
      if (n <= 1) return n;
      let a = 0,
        b = 1;
      for (let i = 2; i <= n; i++) {
        [a, b] = [b, a + b];
      }
      return b;
    });
  }, [kit]);

  return <Calculator />;
}

// 3. Use the hook in any component
function Calculator() {
  const { data, loading, error, run } = useCompute<number, number>('fibonacci');

  return (
    <div>
      <button onClick={() => run(50)} disabled={loading}>
        {loading ? 'Computing...' : 'Calculate Fibonacci(50)'}
      </button>
      {data && <p>Result: {data}</p>}
      {error && <p>Error: {error.message}</p>}
    </div>
  );
}


πŸ“„ License

MIT Β© Ghassen Lassoued


Back to top

Copyright © 2024-2025 Ghassen Lassoued. Distributed under the MIT license.