Last active
August 18, 2019 16:09
-
-
Save hnrchrdl/5da2045c7e72449066cecbc32563faba to your computer and use it in GitHub Desktop.
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>; | |
return ( | |
<> | |
<h1>App: {counter}</h1> | |
<Child isAboveFive={aboveFive} /> | |
{button} | |
</> | |
); | |
}; | |
const Child = ({ isAboveFive, children }) => { | |
console.log("child renders"); | |
return ( | |
<> | |
<h2>Child: {!isAboveFive ? "<= 5" : "> 5"}</h2> | |
{children} | |
</> | |
); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment