内容简介:Use web workers with react hookBefore you start using thisMore examples:
Use web workers with react hook
https://useworker.js.org/
:art:
Features
- Run expensive function without blocking UI ( Show live gif )
- Supports Promises pattern instead of event-messages
- Size:
< 1KB, withzerodependencies - Clear API using hook
:floppy_disk:
Install
npm install --save @koale/useworker
:hammer:
Import
import { useWorker, WORKER_STATUS } from "@koale/useworker";
:orange_book:
Documents
:bread:
Demo
- Sorting : Sorting 50000 random numbers
- Csv : Generate Csv, Parse Csv, Convert to JSON
- External Dependencies Use external scripts inside WebWorkers
⚙ Web Workers
Before you start using this hook , I suggest you to read the Web Worker documentation.
:feet:
Usage
import React from "react";
import { useWorker } from "@koale/useworker";
const numbers = [...Array(5000000)].map(e => ~~(Math.random() * 1000000));
const sortNumbers = nums => nums.sort();
const Example = () => {
const [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>
);
};
:feet:
Examples
More examples: https://github.com/alewin/useWorker/tree/develop/example
:wrench:
Roadmap
- import and use external script inside
useWorkerfunction - import and use local script inside
useWorkerfunction - run multiple instance of the worker
:earth_asia:
Contribute? Bug? New Feature?
The library is experimental so if you find a bug or would like to request a new feature , open an issue
:bulb:
Similar Project
:scroll:
License
MIT © alewin
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
人月神话(40周年中文纪念版)
(美) 布鲁克斯(Brooks, F. P.) 著 / UML China翻译组,汪颖 译 / 清华大学出版社 / 2015-4-1 / 68.00元
在软件领域,很少能有像《人月神话》一样具有深远影响力和畅销不衰的著作。Brooks博士为人们管理复杂项目提供了最具洞察力的见解,既有很多发人深省的观点,又有大量软件工程的实践。本书内容来自Brooks博士在IBM公司SYSTEM/360家族和OS/360中的项目管理经验,该项目堪称软件开发项目管理的典范。该书英文原版一经面世,即引起业内人士的强烈反响,后又译为德、法、日、俄、中、韩等多种文字,全球......一起来看看 《人月神话(40周年中文纪念版)》 这本书的介绍吧!