Skip to content

Instantly share code, notes, and snippets.

@wilsonpage
Created July 28, 2020 09:48
Show Gist options
  • Save wilsonpage/b30394f2ecb47ec4cfe51604f79690fc to your computer and use it in GitHub Desktop.
Save wilsonpage/b30394f2ecb47ec4cfe51604f79690fc to your computer and use it in GitHub Desktop.
const useFoo = () => {
const [bar, setBar] = useState(false);
const [baz, setBaz] = useState(false);
// should not trigger MyComponent to re-render
useEffect(() => {
setTimeout(() => setBar(true), 1000);
}, []);
// should trigger MyComponent to re-render
useEffect(() => {
setTimeout(() => setBaz(true), 2000);
}, []);
return bar && baz;
}
const MyComponent = () => {
const foo = useFoo();
return <h1>{String(foo)}</h1>
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment