initializeWebWorker()
Initializes a Web Worker for the layout calculation.
For example, this function can be used in a Web Worker for asynchronous layout calculation.
// LayoutWorker.ts
import { initializeWebWorker } from '@yworks/yfiles-layout-reactflow/WebWorkerSupport'
initializeWebWorker(self)
// index.tsx
const layoutWorker = new Worker(new URL('./LayoutWorker', import.meta.url), {
type: 'module'
})
const LayoutFlow = () => {
const [nodes] = useNodesState(initialNodes)
const [edges] = useEdgesState(initialEdges)
const { runLayout } = useLayout({ layoutWorker })
return (
<ReactFlow>
<Panel position="top-left">
<button onClick={() => runLayout('HierarchicLayout')}>Layout</button>
</Panel>
</ReactFlow>
)
}
export default function Flow() {
return (
<ReactFlowProvider>
<LayoutFlow />
</ReactFlowProvider>
)
}
Parameters
Name | Description | Type |
---|---|---|
self | The current worker | Window |