UNPKG

@notifyon/react

Version:
33 lines 809 B
// src/index.tsx import { useEffect, useRef } from "react"; import { connect } from "@notifyon/web"; function NotifyOn({ publicKey, userId }) { const instanceRef = useRef(null); const mountedRef = useRef(false); useEffect(() => { if (typeof window === "undefined" || mountedRef.current) { return; } mountedRef.current = true; try { instanceRef.current = connect({ publicKey, userId }); } catch (error) { console.error("Failed to initialize NotifyOn:", error); } return () => { if (instanceRef.current) { instanceRef.current.destroy(); instanceRef.current = null; } mountedRef.current = false; }; }, [publicKey, userId]); return null; } export { NotifyOn }; //# sourceMappingURL=index.mjs.map