• This hook lets you publish the local tracks when the component is ready and unpublish them when the component is unmounted.

    Parameters

    • tracks: (null | ILocalTrack)[]

      The list of local tracks.

    • readyToPublish: boolean = true

      Whether the local tracks are ready to publish. The default value is true.

    • Optional client: IAgoraRTCClient

      Created using the Web SDK's IAgoraRTC.createClient method.

    Returns {
        error: AgoraRTCReactError | null;
        isLoading: boolean;
    }

    Example

    import { useLocalMicrophoneTrack, useLocalCameraTrack, usePublish } from "agora-rtc-react";

    function App() {
    // get audioTrack and videoTrack before publish
    const audioTrack = useLocalMicrophoneTrack();
    const videoTrack = useLocalCameraTrack();
    usePublish([audioTrack, videoTrack]);

    return <></>;
    }