Skip to content

Instantly share code, notes, and snippets.

@ryanswrt
Last active July 25, 2019 04:58
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 ryanswrt/3aaa353bb0fce285c479f71079478007 to your computer and use it in GitHub Desktop.
Save ryanswrt/3aaa353bb0fce285c479f71079478007 to your computer and use it in GitHub Desktop.
const useCallThatCanFail = (query) => {
const [error, setError] = useState();
const [result, setResult] = useState();
useEffect(() => {
callbackThatCanFail(query)
.then((r) => {
setResult(r);
setError(undefined);
}).catch((e) => {
setError(e);
setResult(undefined);
}
)
}, [query]);
return [result, error];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment