UNPKG

@speechmatics/flow-client-react

Version:

React hooks for interacting with the Speechmatics Flow API

22 lines (19 loc) 700 B
"use strict"; "use client"; import { useContext, useEffect } from 'react'; import { FlowContext } from './flow-context.js'; function useFlowEventListener(message, cb) { const context = useContext(FlowContext); if (context === null) { throw new Error("Flow client uninitialized in context"); } return useClientEventListener(context.client, message, cb); } function useClientEventListener(client, eventType, cb) { return useEffect(() => { client.addEventListener(eventType, cb); return () => client?.removeEventListener(eventType, cb); }, [client, eventType, cb]); } export { useClientEventListener, useFlowEventListener }; //# sourceMappingURL=use-flow-event-listener.js.map