Skip to content

Instantly share code, notes, and snippets.

@hnrchrdl
Created August 18, 2019 17:00
Show Gist options
  • Save hnrchrdl/39b953f38f492d5865b8249fcbe2f0ce to your computer and use it in GitHub Desktop.
Save hnrchrdl/39b953f38f492d5865b8249fcbe2f0ce to your computer and use it in GitHub Desktop.
Example 4
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