Last active
November 25, 2019 18:34
-
-
Save Blezzoh/600aad1836f2e3b008956608a7a4c9e0 to your computer and use it in GitHub Desktop.
example of adding your data to the view
This file contains hidden or 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
| componentDidMount() { | |
| // instantiating the worker and adding a listener | |
| this.worker = new Webworker(worker); | |
| this.worker.addEventListener("message", e => { | |
| const { data } = e; | |
| this.setState({ data, isLoading: false }); | |
| }); | |
| } | |
| onClick = () => { | |
| // your event handler that will use a worker | |
| const { numberOfUsers } = this.state; | |
| if (Number.parseInt(numberOfUsers) >= 0) { | |
| this.setState({ isLoading: true }); | |
| this.worker.postMessage({ numberOfUsers }); | |
| } | |
| }; | |
| componentWillUnmount(){ | |
| // terminate the worker once you're done using it | |
| this.worker.terminate() | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment