Last active
April 2, 2021 21:15
-
-
Save westwick/7095d09160f3626605507da9e6c272f8 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 = ({someId}) => { | |
const [searchWorker, setSearchWorker] = useState(); | |
useEffect(() => { | |
const searchWorkerInstance = new SearchWorker(); | |
setSearchWorker(searchWorkerInstance); | |
searchWorkerInstance.onmessage(...); | |
return () => { | |
searchWorkerInstance.terminate(); | |
} | |
}, []); | |
useEffect(() => { | |
if (searchWorker && someId) { | |
searchWorker.postMessage(...); | |
} | |
}, [searchWorker, someId]); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment