Can I have an example with create-react-app?
rainstormza opened this issue ยท 6 comments
rainstormza commented
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.
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>
rainstormza commented
https://codesandbox.io/s/ox85ooo31q
https://spectrum.chat/thread/45727df4-6d3b-4392-a771-218c09329333
mention about the solution in those link.
sometimescool22 commented
@rainstormza @ghengeveld The sandbox is 404'ing, can we get an updated example?
ghengeveld commented
Here's a basic sandbox with CRA: https://codesandbox.io/s/bold-blackwell-vxxth
Lcj-space commented
Here's a basic sandbox with CRA: https://codesandbox.io/s/bold-blackwell-vxxth
The sandbox is 404'ing
ghengeveld commented
Here's another: https://codesandbox.io/s/react-webworker-cra-example-3fjim
ghengeveld commented
The gist is to put the worker file in /public
.