Have ideas to improve npm?Join in the discussion! »

    @jimengio/use-worker
    TypeScript icon, indicating that this package has built-in type declarations

    3.3.0 • Public • Published

    use-worker

    Use web workers with react hook

    npm

    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

    License

    MIT

    Install

    npm i @jimengio/use-worker

    DownloadsWeekly Downloads

    2

    Version

    3.3.0

    License

    MIT

    Unpacked Size

    32.9 kB

    Total Files

    31

    Last publish

    Collaborators

    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar