UNPKG

@adyen/adyen-platform-experience-web

Version:

![Platform Experience header](https://github.com/Adyen/adyen-platform-experience-web/assets/7926613/18094965-9e01-450e-8dc9-ea84e6b22c2b)

30 lines (29 loc) 860 B
import { useState as i, useCallback as u, useEffect as m } from "../external/preact/hooks/dist/hooks.module.js"; import { isFunction as y } from "../utils/value/is.js"; const g = ({ records: s, hasCustomColumn: a = !1, onDataRetrieve: o, mergeCustomData: r }) => { const [f, e] = i(s), [c, l] = i(!1), n = u(async () => { try { if (a && y(o)) { const t = await o(s); if (Array.isArray(t)) e(r({ records: s, retrievedData: (t == null ? void 0 : t.filter(Boolean)) || [] })); else throw new Error("Retrieved data should be an array"); } else e(s); } catch (t) { e(s), console.error(t); } finally { l(!1); } }, [a, o, r, s]); return m(() => { s.length && (l(!0), n()); }, [n, s]), { customRecords: f, loadingCustomRecords: c }; }; export { g as useCustomColumnsData };