Created
April 2, 2021 21:03
-
-
Save westwick/65d7d517b7e7262dc78a9bf0dabfa992 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const SomeComponent = (props) => { | |
const [searchWorker, setSearchWorker] = useState(); | |
useEffect(() => { | |
const searchWorkerInstance = new SearchWorker(); | |
setSearchWorker(searchWorkerInstance); | |
// subscribe to worker messages | |
searchWorkerInstance.onmessage(...); | |
// do something with the worker on component init | |
searchWorkerInstance.postMessage(...); | |
return () => { | |
// this runs when component unmounts | |
searchWorkerInstance.terminate(); | |
} | |
}, []); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment