Skip to content

Instantly share code, notes, and snippets.

@ericelliott
Created March 30, 2020 23:32
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ericelliott/ee6bd23108fbf5e15fa92b66d267641b to your computer and use it in GitHub Desktop.
Save ericelliott/ee6bd23108fbf5e15fa92b66d267641b to your computer and use it in GitHub Desktop.
usePromise hook
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