Created
May 11, 2020 13:40
-
-
Save finom/f97a6a4f344690a2486668bb3e207e38 to your computer and use it in GitHub Desktop.
[finom/use-promise-effect] A promise effect hook
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
/* | |
Usage: | |
usePromiseEffect(async => () => { | |
await fetch(foo); | |
// ... | |
}) | |
*/ | |
import { useEffect } from 'react'; | |
export default function usePromiseEffect(callback, memos) { | |
return useEffect(() => { | |
Promise.resolve(callback()).catch((e) => { throw e; }); | |
}, memos); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment