async-library/react-webworker

Can I have an example with create-react-app?

rainstormza opened this issue ยท 6 comments

Can I have an example with create-react-app?

I've tried to implement this lib within create-react-app project but it does not work.
It seems my worker.js has something wrong.

image

component.js

 <WebWorker url="/worker.js">
    {({ data, error, postMessage }) => {
      if (error) return `Something went wrong: ${error.message}`
      if (data)
        return (
          <div>
            <strong>Received some data:</strong>
            <pre>{JSON.stringify(data, null, 2)}</pre>
          </div>
        )
      return <button onClick={() => postMessage('hello')}>Hello</button>
    }}
  </WebWorker>

https://codesandbox.io/s/ox85ooo31q

@rainstormza @ghengeveld The sandbox is 404'ing, can we get an updated example?

Here's a basic sandbox with CRA: https://codesandbox.io/s/bold-blackwell-vxxth

Here's a basic sandbox with CRA: https://codesandbox.io/s/bold-blackwell-vxxth
The sandbox is 404'ing

The gist is to put the worker file in /public.