UNPKG

react-adonis-transmit

Version:
43 lines (39 loc) 1.42 kB
import React, { ReactNode } from 'react'; import { Transmit } from '@adonisjs/transmit-client'; /** * The shape of the context value that will be provided to consumers */ interface TransmitContextValue { /** The underlying Transmit instance */ transmit: Transmit; /** * Subscribe to a channel and receive events * Returns an unsubscribe function that should be called to clean up */ subscribe: (channel: string, callback: (event: any) => void) => () => void; } /** * Props for the TransmitProvider component */ interface TransmitProviderProps { children: ReactNode; /** Base URL of your Adonis API */ baseUrl: string; /** Enable debug logging */ enableLogging?: boolean; /** Global handler for all messages */ onMessage?: (channel: string, event: any) => void; /** Auth header value */ authHeader?: string; } /** * Provider component that manages Transmit instance and subscriptions * Handles authentication, connection lifecycle, and subscription cleanup */ declare function TransmitProvider({ children, baseUrl, onMessage, authHeader, enableLogging, }: TransmitProviderProps): React.JSX.Element; /** * Hook to access the Transmit context * Must be used within a TransmitProvider */ declare function useTransmit(): TransmitContextValue; export { type TransmitContextValue, TransmitProvider, type TransmitProviderProps, useTransmit };