Created
August 18, 2019 17:00
-
-
Save hnrchrdl/39b953f38f492d5865b8249fcbe2f0ce to your computer and use it in GitHub Desktop.
Example 4
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
const App = () => { | |
const [counter, setCounter] = useState(0); | |
const [aboveFive, setAboveFive] = useState(false); | |
const increment = () => { | |
setCounter(n => n + 1); | |
}; | |
useEffect(() => { | |
if (counter > 5) { | |
setAboveFive(true); | |
} | |
}, [counter]); | |
const button = <button onClick={increment}>++</button>; | |
const child = useMemo(() => <Child isAboveFive={aboveFive} />, [aboveFive]); | |
return ( | |
<> | |
<h1>App: {counter}</h1> | |
{child} | |
{button} | |
</> | |
); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment