Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jdeurt/rewrk
Dead simple React web workers.
https://github.com/jdeurt/rewrk
Last synced: about 1 month ago
JSON representation
Dead simple React web workers.
- Host: GitHub
- URL: https://github.com/jdeurt/rewrk
- Owner: jdeurt
- License: mit
- Created: 2022-12-24T15:27:38.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2022-12-28T04:01:57.000Z (about 2 years ago)
- Last Synced: 2024-11-07T05:43:28.228Z (about 2 months ago)
- Language: TypeScript
- Size: 38.1 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: license
Awesome Lists containing this project
README
# Rewrk
[![Version](https://img.shields.io/npm/v/sgex.svg)](https://www.npmjs.com/package/rewrk)
![Prerequisite](https://img.shields.io/badge/node-%3E%3D16-blue.svg)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](#)> Dead simple React web workers.
## API
### `useWorker>(dynamicImport: Promise, options?: WorkerOptions): ProxiedWorkerMethods`
Creates a [worker](https://developer.mozilla.org/en-US/docs/Web/API/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
```jsx
import { useWorker } from "rewrk";const WorkerComponent = () => {
const worker = useWorker(import("./worker"));return worker.doSomething()}>Do something;
};
```## License
MIT © [Juan de Urtubey](https://jdeurt.xyz)