Created
March 7, 2020 08:49
-
-
Save DennyScott/ecd7645d85b6fcb62965b6fe1b240775 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
function App() { | |
const [index, setIndex] = useState(0); | |
const notMemoized = () => { | |
console.log("Rendered no callback"); | |
}; | |
const memoized = useCallback(() => console.log("Rendered callback"), []); | |
return ( | |
<div className="App"> | |
<h1>Hello CodeSandbox</h1> | |
<h2>Start editing to see some magic happen!</h2> | |
<DemoEffect dep={notMemoized} /> | |
<DemoEffect dep={memoized} /> | |
<button onClick={() => setIndex(index + 1)}>Rerender</button> | |
</div> | |
); | |
} | |
function DemoEffect({ dep }) { | |
useEffect(() => dep(), [dep]); | |
return <div>Demo Effect</div>; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment