UNPKG

bananahooks

Version:

"Collection" of custom React Hooks.

3 lines (2 loc) 624 B
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports,require("react")):"function"==typeof define&&define.amd?define(["exports","react"],n):(e=e||self,n(e.bananahooks={},e.React))}(this,function(e,n){"use strict";e.usePromise=function(e,t){const[r,o]=n.useState({value:t,error:null,isPending:!0});n.useEffect(()=>{const n="function"==typeof e?e():e;let r=!0;return n.then(e=>r?o({value:e,error:null,isPending:!1}):null).catch(e=>r?o({value:t,error:e,isPending:!1}):null),()=>{r=!1}},[e,t]);const{value:u,error:i,isPending:s}=r;return[u,i,s]}}); //# sourceMappingURL=bananahooks.umd.production.js.map