UNPKG

one

Version:

One is a React framework for web, iOS, and Android apps.

1 lines • 1.41 kB
{"version":3,"file":"useThenable.js","names":[],"sources":["esm/fork/useThenable.js"],"sourcesContent":["import * as React from \"react\";\nfunction useThenable(create) {\n const [promise] = React.useState(create);\n let initialState = [false, void 0];\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}\nexport {\n useThenable\n};\n//# sourceMappingURL=useThenable.js.map\n"],"mappings":";;;AACA,SAAS,YAAY,QAAQ;CAC3B,MAAM,CAAC,WAAW,MAAM,SAAS,MAAM;CACvC,IAAI,eAAe,CAAC,OAAO,KAAK,CAAC;CACjC,QAAQ,MAAM,WAAW;EACvB,eAAe,CAAC,MAAM,MAAM;CAC9B,CAAC;CACD,MAAM,CAAC,OAAO,YAAY,MAAM,SAAS,YAAY;CACrD,MAAM,CAAC,YAAY;CACnB,MAAM,gBAAgB;EACpB,IAAI,YAAY;EAChB,MAAM,UAAU,YAAY;GAC1B,IAAI;GACJ,IAAI;IACF,SAAS,MAAM;GACjB,UAAU;IACR,IAAI,CAAC,WAAW;KACd,SAAS,CAAC,MAAM,MAAM,CAAC;IACzB;GACF;EACF;EACA,IAAI,CAAC,UAAU;GACb,QAAQ;EACV;EACA,aAAa;GACX,YAAY;EACd;CACF,GAAG,CAAC,SAAS,QAAQ,CAAC;CACtB,OAAO;AACT"}