mirror of
https://github.com/hanzoai/next.js.git
synced 2026-09-24 17:00:51 +00:00
- Also process `new Worker()` if there are options - Then remove the `type: module` from the options at runtime (as Webpack also does apparently). The alternative would be to keep the `type: module` and ESM imports instead in the worker.
25 lines
557 B
JavaScript
25 lines
557 B
JavaScript
'use client'
|
|
import { useState } from 'react'
|
|
|
|
export default function Home() {
|
|
const [state, setState] = useState('default')
|
|
return (
|
|
<div>
|
|
<button
|
|
onClick={() => {
|
|
const worker = new Worker(new URL('../worker', import.meta.url), {
|
|
type: 'module',
|
|
})
|
|
worker.addEventListener('message', (event) => {
|
|
setState(event.data)
|
|
})
|
|
}}
|
|
>
|
|
Get web worker data
|
|
</button>
|
|
<p>Worker state: </p>
|
|
<p id="worker-state">{state}</p>
|
|
</div>
|
|
)
|
|
}
|