How to handle CPU-intensive tasks
Web workers make the application fast by running CPU-intensive tasks on a different thread other than the main thread.
npm install -D workerize-loaderimport {getItems} from '../workerized-expensive'import makeItemsWorker from 'workerize!./expensive'
const {getItems} = makeItemsWorker()
export {getItems}import React from 'react'
import {getItems} from '../workerized-expensive'
import {useAsync} from '../utils'
const {data: allItems, run} = useAsync({data: [], status: 'pending'})
React.useEffect(() => {
run(getItems(inputValue))
}, [inputValue, run])
const items = allItems.slice()
Last updated