UNPKG

@duongtrungnguyen/next-helper

Version:
23 lines 889 B
import { Socket } from "socket.io-client"; /** * Custom hook to manage a WebSocket connection with a specified namespace. * * @param {string} namespace - The namespace for the WebSocket connection. * @returns {Object} An object containing the WebSocket instance and connection status. * @returns {Socket | null} socket - The WebSocket instance. * @returns {boolean} isConnected - The connection status of the WebSocket. * * @example * const { socket, isConnected } = useSocket('chat'); * * useEffect(() => { * if (isConnected) { * socket?.emit('message', 'Hello World'); * } * }, [isConnected]); */ export declare function useSocket(namespace: string): { socket: Socket<import("@socket.io/component-emitter").DefaultEventsMap, import("@socket.io/component-emitter").DefaultEventsMap> | null; isConnected: boolean; }; //# sourceMappingURL=use-socket.d.ts.map