UNPKG

react-deck-link

Version:

React SDK for integrating Deck Link

31 lines (30 loc) 1.02 kB
import { useEffect as a, useState as l, useMemo as m, useRef as E } from "react"; const f = (t, { onerror: n, onload: o }) => a(() => { const e = document.createElement("script"); return e.src = t, e.async = !0, e.onload = o || null, e.onerror = n || null, document.body.appendChild(e), () => { document.body.removeChild(e); }; }, [t, n, o]), p = () => { }, D = "https://link.deck.co/link-initialize.js", x = (t) => { var d, u; const { linkSdkUrl: n = D, ...o } = t, [e, s] = l(!1), [c, i] = l(), k = m( () => ({ onload: () => i(window.Deck), onerror: () => { s(!0), console.error("react-deck-link: Error loading Deck SDK"); } }), [s, i] ); f(n, k); const r = E(void 0); return r.current = c == null ? void 0 : c.create(o), { exit: ((d = r.current) == null ? void 0 : d.exit.bind(r.current)) || p, open: ((u = r.current) == null ? void 0 : u.open.bind(r.current)) || p, isError: e, isReady: !!r.current }; }; export { x as useDeckLink };