@jimengio/use-worker
v3.3.0
Published
useWorker() - Web worker using React hook
Downloads
9
Readme
use-worker
Use web workers with react hook
Fork: https://github.com/alewin/useWorker
Usage
yarn add @jimengio/use-worker
import React from "react";
import { useWorker } from "@jimengio/use-worker";
const numbers = [...Array(5000000)].map((e) => ~~(Math.random() * 1000000));
const sortNumbers = (nums) => nums.sort();
const Example = () => {
const { callback: sortWorker } = useWorker(sortNumbers);
const runSort = async () => {
const result = await sortWorker(numbers); // non-blocking UI
console.log("End.");
};
return (
<button type="button" onClick={runSort}>
Run Sort
</button>
);
};
Dev
# build package
yarn build
# tests
yarn test
# lint
yarn eslint