{"ast":null,"code":"import _asyncToGenerator from \"@babel/runtime/helpers/asyncToGenerator\";\nimport _slicedToArray from \"@babel/runtime/helpers/slicedToArray\";\nimport * as React from 'react';\nexport default function useThenable(create) {\n  var _React$useState = React.useState(create),\n    _React$useState2 = _slicedToArray(_React$useState, 1),\n    promise = _React$useState2[0];\n  var initialState = [false, undefined];\n  promise.then(function (result) {\n    initialState = [true, result];\n  });\n  var _React$useState3 = React.useState(initialState),\n    _React$useState4 = _slicedToArray(_React$useState3, 2),\n    state = _React$useState4[0],\n    setState = _React$useState4[1];\n  var _state = _slicedToArray(state, 1),\n    resolved = _state[0];\n  React.useEffect(function () {\n    var cancelled = false;\n    var resolve = function () {\n      var _ref = _asyncToGenerator(function* () {\n        var result;\n        try {\n          result = yield promise;\n        } finally {\n          if (!cancelled) {\n            setState([true, result]);\n          }\n        }\n      });\n      return function resolve() {\n        return _ref.apply(this, arguments);\n      };\n    }();\n    if (!resolved) {\n      resolve();\n    }\n    return function () {\n      cancelled = true;\n    };\n  }, [promise, resolved]);\n  return state;\n}","map":{"version":3,"sources":["useThenable.tsx"],"names":["React","useThenable","create","promise","useState","initialState","undefined","then","result","state","setState","resolved","useEffect","cancelled","resolve"],"mappings":";;AAAA,OAAO,KAAKA,KAAK,MAAM,OAAO;AAE9B,eAAe,SAASC,WAAW,CAAIC,MAA4B,EAAE;EACnE,IAAA,eAAA,GAAkBF,KAAK,CAACI,QAAQ,CAACF,MAAM,CAAC;IAAA,gBAAA,GAAA,cAAA,CAAA,eAAA;IAAjCC,OAAO,GAAA,gBAAA;EAEd,IAAIE,YAAsC,GAAG,CAAC,KAAK,EAAEC,SAAS,CAAC;EAG/DH,OAAO,CAACI,IAAI,CAAEC,UAAAA,MAAM,EAAK;IACvBH,YAAY,GAAG,CAAC,IAAI,EAAEG,MAAM,CAAC;EAC/B,CAAC,CAAC;EAEF,IAAA,gBAAA,GAA0BR,KAAK,CAACI,QAAQ,CAACC,YAAY,CAAC;IAAA,gBAAA,GAAA,cAAA,CAAA,gBAAA;IAA/CI,KAAK,GAAA,gBAAA;IAAEC,QAAQ,GAAA,gBAAA;EACtB,IAAA,MAAA,GAAA,cAAA,CAAmBD,KAAK;IAAjBE,QAAQ,GAAA,MAAA;EAEfX,KAAK,CAACY,SAAS,CAAC,YAAM;IACpB,IAAIC,SAAS,GAAG,KAAK;IAErB,IAAMC,OAAO;MAAA,IAAA,IAAA,GAAA,iBAAA,CAAG,aAAY;QAC1B,IAAIN,MAAM;QAEV,IAAI;UACFA,MAAM,SAASL,OAAO;QACxB,CAAC,SAAS;UACR,IAAI,CAACU,SAAS,EAAE;YACdH,QAAQ,CAAC,CAAC,IAAI,EAAEF,MAAM,CAAC,CAAC;UAC1B;QACF;MACF,CAAC;MAAA,gBAVKM,OAAO,CAAA;QAAA,OAAA,IAAA,CAAA,KAAA,OAAA,SAAA;MAAA;IAAA,GAUZ;IAED,IAAI,CAACH,QAAQ,EAAE;MACbG,OAAO,CAAA,CAAE;IACX;IAEA,OAAO,YAAM;MACXD,SAAS,GAAG,IAAI;IAClB,CAAC;EACH,CAAC,EAAE,CAACV,OAAO,EAAEQ,QAAQ,CAAC,CAAC;EAEvB,OAAOF,KAAK;AACd","sourceRoot":"../../src","sourcesContent":["import * as React from 'react';\nexport default function useThenable(create) {\n  const [promise] = React.useState(create);\n  let initialState = [false, undefined];\n\n  // Check if our thenable is synchronous\n  promise.then(result => {\n    initialState = [true, result];\n  });\n  const [state, setState] = React.useState(initialState);\n  const [resolved] = state;\n  React.useEffect(() => {\n    let cancelled = false;\n    const resolve = async () => {\n      let result;\n      try {\n        result = await promise;\n      } finally {\n        if (!cancelled) {\n          setState([true, result]);\n        }\n      }\n    };\n    if (!resolved) {\n      resolve();\n    }\n    return () => {\n      cancelled = true;\n    };\n  }, [promise, resolved]);\n  return state;\n}\n//# sourceMappingURL=useThenable.js.map"]},"metadata":{},"sourceType":"module"}