Giter Site home page Giter Site logo

pocesar / react-use-comlink Goto Github PK

View Code? Open in Web Editor NEW
45.0 2.0 4.0 125 KB

Three ways to use Comlink web workers through React Hooks (and in a typesafe manner).

License: MIT License

TypeScript 60.47% HTML 1.09% JavaScript 38.45%
react reactjs react-hooks react-hook comlink webworker webworkers web worker hooks mjs umd typescript web-workers async

react-use-comlink's Issues

Failing under create-react-app dev server

When running the example under the create-react-app dev server (started via npm run start), the workers don't work on first load. However, after editing a source file the workers will start to work. If you reload the page, the workers again will stop working.

My source code is here: https://github.com/acbeers/worker-test

What I see:

  • on first load, the code in useMemo is called twice. On the first call, the output at line 25 (console.log(res)) shows a resolved promise. On the second call, the promise is shown as pending.
  • when clicking the "Increase from comlink" button, the output at line 31 (console.log(instance)) shows that the promise is still pending.
  • after editing the source and saving, useMemo is again called twice. This time, the output at line 25 shows both promises resolve. And, the button will now work.

Have you gotten this example to work under cra's development server? Many thanks for any advice you can offer

Unexpected token '<'

I created a simple object similar to the example:

import { expose } from 'comlink'

export const SortWorker = {
  hello: 'world',
  sort() {
    return 'sort worker ran!'
  },
}

expose(SortWorker)

But I see this in the console: Uncaught SyntaxError: Unexpected token '<'

I am using create-react-app with hooks.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.