Skip to content

Instantly share code, notes, and snippets.

@hnrchrdl
Created August 18, 2019 18:01
Show Gist options
  • Save hnrchrdl/6509b5eb0c826cc8a5ecae295f83844b to your computer and use it in GitHub Desktop.
Save hnrchrdl/6509b5eb0c826cc8a5ecae295f83844b to your computer and use it in GitHub Desktop.
Example 8
const App = () => {
const [counter, setCounter] = useState(0);
const [aboveFive, setAboveFive] = useState(false);
const increment = useCallback(() => {
setCounter(n => n + 1);
}, []);
useEffect(() => {
if (counter > 5) {
setAboveFive(true);
}
}, [counter]);
const button = useMemo(() => <button onClick={increment}>++</button>, [
increment
]);
return (
<>
<h1>App: {counter}</h1>
<Child isAboveFive={aboveFive}>{button}</Child>
</>
);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment