Created
March 30, 2020 23:32
-
-
Save ericelliott/ee6bd23108fbf5e15fa92b66d267641b to your computer and use it in GitHub Desktop.
usePromise 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
import { useRef } from 'react'; | |
const usePromise = () => { | |
const ref = []; | |
const container = useRef(ref); | |
ref[0] = new Promise((resolve, reject) => { | |
ref[1] = resolve; | |
ref[2] = reject; | |
}); | |
// [promise, resolve, reject] | |
return container.current; | |
}; | |
export { usePromise }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment