UNPKG

@thisisagile/easy-react

Version:

Straightforward library building micro applications in react

1 lines 701 B
{"version":3,"sources":["../../src/utils/useOnce.ts"],"sourcesContent":["import { DependencyList, useEffect, useState } from 'react';\n\nexport type UseOnceOptions<E> = {\n deps?: DependencyList;\n initial?: Partial<E>;\n};\n\nexport function useOnce<E>(f: () => Promise<E>, options?: UseOnceOptions<E>): [E] {\n const [item, setItem] = useState(options?.initial as E);\n useEffect(() => void f().then(i => setItem(i)), options?.deps ?? []);\n return [item];\n}\n"],"mappings":";AAAA,SAAyB,WAAW,gBAAgB;AAO7C,SAAS,QAAW,GAAqB,SAAkC;AAChF,QAAM,CAAC,MAAM,OAAO,IAAI,SAAS,SAAS,OAAY;AACtD,YAAU,MAAM,KAAK,EAAE,EAAE,KAAK,OAAK,QAAQ,CAAC,CAAC,GAAG,SAAS,QAAQ,CAAC,CAAC;AACnE,SAAO,CAAC,IAAI;AACd;","names":[]}