Last active
December 19, 2020 09:29
-
-
Save madeinfree/581e4fd2bfee2d840c85e2f54f55ce88 to your computer and use it in GitHub Desktop.
Revisions
-
madeinfree revised this gist
Dec 19, 2020 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -10,7 +10,7 @@ export default function App() { const data = e.data; setSum(data); }); worker.postMessage([0, 1000000000]); }, []); return ( -
madeinfree revised this gist
Dec 19, 2020 . No changes.There are no files selected for viewing
-
madeinfree created this gist
Dec 19, 2020 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,22 @@ import React, { useState, useEffect } from "react"; import "./styles.css"; export default function App() { const [sum, setSum] = useState(0); useEffect(() => { const worker = new Worker("./computing.js"); worker.addEventListener("message", (e) => { const data = e.data; setSum(data); }); worker.postMessage([0, 200]); }, []); return ( <div className="App"> <h1>Hello CodeSandbox</h1> <h2>Count Sum: {sum}</h2> </div> ); } 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,8 @@ onmessage = (e) => { const [num1, num2] = e.data; let sum = 0; for (let i = num1; i < num2; i++) { sum += i; } postMessage(sum); };