Skip to content

Instantly share code, notes, and snippets.

@jvergeldedios
Created February 11, 2020 23:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jvergeldedios/1e6d592a3b963232974b0d02dc74d65b to your computer and use it in GitHub Desktop.
Save jvergeldedios/1e6d592a3b963232974b0d02dc74d65b to your computer and use it in GitHub Desktop.
//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