rewrk
TypeScript icon, indicating that this package has built-in type declarations

1.2.11 • Public • Published

Rewrk

Version Prerequisite License: MIT

Dead simple React web workers.

API

useWorker<T extends Record<string, unknown>>(dynamicImport: Promise<T>, options?: WorkerOptions): ProxiedWorkerMethods<T>

Creates a worker from a dynamic import and returns a proxy object that can be used to call the worker's exported functions.

Arguments

  • dynamicImport - A function that returns dynamic import of the worker module. The module must export at least one function. Non-function exports will be stripped away.
  • options? - Options to pass to the worker constructor. By default the type option is set to "module".

Returns

A proxy object that can be used to call the worker's exported functions. The proxy object will be available immidiately despite the dynamic import returning a Promise.

Usage

import { useWorker } from "rewrk";

const WorkerComponent = () => {
    const worker = useWorker(import("./worker"));

    return <button onClick={() => worker.doSomething()}>Do something</button>;
};

License

MIT © Juan de Urtubey

Readme

Keywords

Package Sidebar

Install

npm i rewrk

Weekly Downloads

0

Version

1.2.11

License

MIT

Unpacked Size

15.3 kB

Total Files

19

Last publish

Collaborators

  • jdeurt