Skip to content

bluesad/example-react-use-web-worker

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

React useWebWorker hook

This project was bootstrapped with Create React App.

Author: Andrzej Kowal.

Available Scripts

To check how it actually works - just run yarn start or npm start. After open Open http://localhost:3000 to view it in the browser.

There also will be some console.log calls, som open the browser console too.

What's going on?

The article: https://dev.to/sumankalia/web-workers-in-reactjs-4bc7

It's an example (basic) implementation of hook useWebWorker which can be used to run worker inside of the React component. Hook also will handle running state, error and the final worker execution result.

Worker script: src/worker/script.ts.

useWebWorker hook: src/worker/useWebWorker.ts

Helpful utility for creating new Worker instance: src/worker/webWorker.ts

There are also some pure components in components directory. They only display some data based on props.

Everything connected in single place: src/App.tsx

Let me know what do you think in the comments here: https://dev.to/sumankalia/web-workers-in-reactjs-4bc7

About

useWebWorker hook for React - basic example

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • TypeScript 78.4%
  • HTML 17.8%
  • CSS 3.8%