{"version":3,"sources":["useThenable.tsx"],"names":["useThenable","create","promise","React","useState","initialState","undefined","then","result","state","setState","resolved","useEffect","cancelled","resolve"],"mappings":";;;;;;;AAAA;;;;;;AAEe,SAASA,WAAT,CAAwBC,MAAxB,EAAsD;AACnE,QAAM,CAACC,OAAD,IAAYC,KAAK,CAACC,QAAN,CAAeH,MAAf,CAAlB;AAEA,MAAII,YAAsC,GAAG,CAAC,KAAD,EAAQC,SAAR,CAA7C,CAHmE,CAKnE;;AACAJ,EAAAA,OAAO,CAACK,IAAR,CAAcC,MAAD,IAAY;AACvBH,IAAAA,YAAY,GAAG,CAAC,IAAD,EAAOG,MAAP,CAAf;AACD,GAFD;AAIA,QAAM,CAACC,KAAD,EAAQC,QAAR,IAAoBP,KAAK,CAACC,QAAN,CAAeC,YAAf,CAA1B;AACA,QAAM,CAACM,QAAD,IAAaF,KAAnB;AAEAN,EAAAA,KAAK,CAACS,SAAN,CAAgB,MAAM;AACpB,QAAIC,SAAS,GAAG,KAAhB;;AAEA,UAAMC,OAAO,GAAG,YAAY;AAC1B,UAAIN,MAAJ;;AAEA,UAAI;AACFA,QAAAA,MAAM,GAAG,MAAMN,OAAf;AACD,OAFD,SAEU;AACR,YAAI,CAACW,SAAL,EAAgB;AACdH,UAAAA,QAAQ,CAAC,CAAC,IAAD,EAAOF,MAAP,CAAD,CAAR;AACD;AACF;AACF,KAVD;;AAYA,QAAI,CAACG,QAAL,EAAe;AACbG,MAAAA,OAAO;AACR;;AAED,WAAO,MAAM;AACXD,MAAAA,SAAS,GAAG,IAAZ;AACD,KAFD;AAGD,GAtBD,EAsBG,CAACX,OAAD,EAAUS,QAAV,CAtBH;AAwBA,SAAOF,KAAP;AACD","sourcesContent":["import * as React from 'react';\n\nexport default function useThenable(create: () => PromiseLike) {\n const [promise] = React.useState(create);\n\n let initialState: [boolean, T | undefined] = [false, undefined];\n\n // Check if our thenable is synchronous\n promise.then((result) => {\n initialState = [true, result];\n });\n\n const [state, setState] = React.useState(initialState);\n const [resolved] = state;\n\n React.useEffect(() => {\n let cancelled = false;\n\n const resolve = async () => {\n let result;\n\n try {\n result = await promise;\n } finally {\n if (!cancelled) {\n setState([true, result]);\n }\n }\n };\n\n if (!resolved) {\n resolve();\n }\n\n return () => {\n cancelled = true;\n };\n }, [promise, resolved]);\n\n return state;\n}\n"]}