GitHub

Source

useTrackToggle

The useTrackToggle hook is used to implement the TrackToggle component and returns state and functionality of the given track.

Import

import { useTrackToggle } from "@livekit/components-react";

Usage

const { buttonProps, enabled } = useTrackToggle(trackRef);
return <button {...buttonProps}>{enabled ? "disable" : "enable"}</button>;

Returns

{
toggle: ((forceState?: boolean) => Promise<void>) |
((
forceState?: boolean,
captureOptions?: import("@livekit/components-core").CaptureOptionsBySource<T> | undefined
) => Promise<boolean | undefined>);
enabled: boolean;
pending: boolean;
track: import("livekit-client").LocalTrackPublication | undefined;
buttonProps: React.ButtonHTMLAttributes<HTMLButtonElement>;
}