/bad.js Secret
Last active
May 31, 2020 10:38
Revisions
-
Siemko revised this gist
May 31, 2020 . 2 changed files with 78 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,39 @@ import React from "react"; import ReactDOM from "react-dom"; function calculateSum(x, y) { let i = 0; let wait = Math.random() * 1000000000 + 1000000000; while (i < wait) { i++; } return x + y; } function Sum({ x, y }) { const sum = React.useMemo(() => calculateSum(x, y), [x, y]); return ( <div> The sum of {x} and {y} is {sum}. </div> ); } function Counter() { const [count, setCount] = React.useState(0); const increment = () => setCount(c => c + 1); return ( <div> <button onClick={increment}>The count is {count}</button> <Sum x={2} y={3} /> </div> ); } const rootElement = document.getElementById("root"); ReactDOM.render( <React.StrictMode> <Counter /> </React.StrictMode>, rootElement ); 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,39 @@ import React from "react"; import ReactDOM from "react-dom"; function calculateSum(x, y) { let i = 0; let wait = Math.random() * 1000000000 + 1000000000; while (i < wait) { i++; } return x + y; } function Sum({ x, y }) { const sum = calculateSum(x, y); return ( <div> The sum of {x} and {y} is {sum}. </div> ); } function Counter() { const [count, setCount] = React.useState(0); const increment = () => setCount(c => c + 1); return ( <div> <button onClick={increment}>The count is {count}</button> <Sum x={2} y={3} /> </div> ); } const rootElement = document.getElementById("root"); ReactDOM.render( <React.StrictMode> <Counter /> </React.StrictMode>, rootElement ); -
Siemko revised this gist
May 31, 2020 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -23,7 +23,7 @@ function Good(props) { const rootElement = document.getElementById("root"); ReactDOM.render( <React.StrictMode> <Good spinner={<Spinner label="good" />} /> </React.StrictMode>, rootElement ); -
Siemko revised this gist
May 31, 2020 . 2 changed files with 16 additions and 10 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,18 +1,21 @@ import React from "react"; import ReactDOM from "react-dom"; function Spinner({ label }) { console.log(`[${label}] I started spinning`); setTimeout(() => { console.log(`[${label}] I stopped spinning!`); }, 1000 + Math.random() * 1000); return null; } function Bad() { const [count, setCount] = React.useState(0); const increment = () => setCount(c => c + 1); return ( <div> <button onClick={increment}>[Bad] The count is {count}</button> <Spinner label="bad" /> </div> ); } 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 charactersOriginal file line number Diff line number Diff line change @@ -1,8 +1,11 @@ import React from "react"; import ReactDOM from "react-dom"; function Spinner({ label }) { console.log(`[${label}] I started spinning`); setTimeout(() => { console.log(`[${label}] I stopped spinning!`); }, 1000 + Math.random() * 1000); return null; } @@ -11,16 +14,16 @@ function Good(props) { const increment = () => setCount(c => c + 1); return ( <div> <button onClick={increment}>[Good] The count is {count}</button> {props.spinner} </div> ); } const rootElement = document.getElementById("root"); ReactDOM.render( <React.StrictMode> <Good spinner={<Spinner label="count" />} /> </React.StrictMode>, rootElement ); -
Siemko revised this gist
May 30, 2020 . 2 changed files with 52 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,26 @@ import React from "react"; import ReactDOM from "react-dom"; function Logger({ label }) { console.log(`${label} render!`); return null; } function Bad(props) { const [count, setCount] = React.useState(0); const increment = () => setCount(c => c + 1); return ( <div> <button onClick={increment}>The count is {count}</button> <Logger label="counter" /> </div> ); } const rootElement = document.getElementById("root"); ReactDOM.render( <React.StrictMode> <Bad /> </React.StrictMode>, rootElement ); 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,26 @@ import React from "react"; import ReactDOM from "react-dom"; function Logger({ label }) { console.log(`${label} render!`); return null; } function Good(props) { const [count, setCount] = React.useState(0); const increment = () => setCount(c => c + 1); return ( <div> <button onClick={increment}>The count is {count}</button> {props.logger} </div> ); } const rootElement = document.getElementById("root"); ReactDOM.render( <React.StrictMode> <Good logger={<Logger label="count" />} /> </React.StrictMode>, rootElement ); -
Siemko revised this gist
May 30, 2020 . No changes.There are no files selected for viewing
-
Siemko created this gist
May 30, 2020 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,13 @@ import * as React from "react"; const Text = React.lazy(() => import("./text")); export default function App() { return ( <div className="App"> <React.Suspense fallback={<p>Loading...</p>}> <Text /> </React.Suspense> </div> ); } 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,5 @@ import * as React from "react"; export default function Text() { return <p>This is Text component</p>; }