UNPKG

react-use-action-cable-ts

Version:

Hooks to easily use Rails Action Cable in your React application

31 lines (30 loc) 1.04 kB
import { ChannelNameWithParams, Consumer, Subscription } from "@rails/actioncable"; type Action = Parameters<Subscription["perform"]>[0]; type Payload = Parameters<Subscription["perform"]>[1]; export type ActionCableOptions = { verbose?: boolean; }; export declare function useActionCable(url: string, { verbose }?: ActionCableOptions): { actionCable: Consumer; }; export type ChannelOptions = { verbose: boolean; receiveCamelCase: boolean; sendSnakeCase: boolean; }; export declare function useChannel<T>(actionCable: Consumer, { verbose, receiveCamelCase, sendSnakeCase }?: ChannelOptions): { subscribe: (data: ChannelNameWithParams, callbacks: { received?: (x: T) => void; rejected?: () => void; initialized?: () => void; connected?: () => void; disconnected?: () => void; }) => void; unsubscribe: () => void; send: ({ action, payload, useQueue }: { action: Action; payload: Payload; useQueue: boolean; }) => void; }; export {};