UNPKG

@open-condo/miniapp-utils

Version:

A set of helper functions / components / hooks used to build new condo apps fast

26 lines 824 B
// src/hooks/useSetPageActionsHandlers.ts import { useEffect, useRef } from "react"; function useSetPageActionsHandlers(bridge, handlers) { const handlersRef = useRef(handlers); useEffect(() => { handlersRef.current = handlers; }, [handlers]); useEffect(() => { const listener = (event) => { if (event.type !== "CondoWebAppActionClickEvent") return; if ("actionId" in event.data && typeof event.data.actionId === "string") { const { actionId } = event.data; const handler = handlersRef.current[actionId]; handler == null ? void 0 : handler(actionId); } }; bridge.subscribe(listener); return () => { bridge.unsubscribe(listener); }; }, [bridge]); } export { useSetPageActionsHandlers }; //# sourceMappingURL=useSetPageActionsHandlers.mjs.map