Created
February 11, 2020 23:49
-
-
Save jvergeldedios/1e6d592a3b963232974b0d02dc74d65b to your computer and use it in GitHub Desktop.
This file contains 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
//useSomethingAsync.js | |
export default () => { | |
const [thing, setThing] = useState(null); | |
useEffect(() => { | |
doAsyncThing().then(result => setThing(result)); | |
}, []); | |
return thing; | |
}; | |
//useSomeOtherThing.js | |
export default () => { | |
const thing = useSomethingAsync(); | |
useEffect(() => { | |
if (thing) { | |
doSomethingWithThing(thing); | |
} | |
}, [thing]); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment