use-webworker

A react hook wrapper over web worker API. Exposing worker messages as state.

Usage no npm install needed!

<script type="module">
  import useWebworker from 'https://cdn.skypack.dev/use-webworker';
</script>

README

use-webworker

A react hook wrapper over webworker exposing message data from worker as state

Build Status version min size mingzip size license

dependancies downloads all contributors code of conduct

stargazers number of forks

:clap: & :heart: to auto badger for making badging simple

Install

npm install --save use-webworker

Usage

import useWebworker from 'use-webworker'

function Example {
  const {isProcessing, data: dataFromWorker } = useWebworker({
    url: '/worker.js', // available at %PUBLIC_URL%/worker.js
    data: {}
  });
  if(isProcessing) {
    return <h1>Loading...</h1>
  }
  return <h1>{dataFromWorker}</h1>
}

License

MIT © technikhil314