# React Hooks (@zoom/videosdk-react) Official React SDK that provides custom hooks and components for integrating Zoom Video SDK into React apps. ## Installation ```bash npm install @zoom/videosdk npm install https://github.com/zoom/videosdk-react/releases/download/v0.0.1/zoom-videosdk-react-0.0.1.tgz ``` **Prerequisites:** - React 18+ - Zoom Video SDK account and credentials ## Quick Start ```tsx import { useSession, useSessionUsers, VideoPlayerComponent, VideoPlayerContainerComponent } from '@zoom/videosdk-react'; function VideoChat() { const { isInSession, isLoading, isError } = useSession( "session123", "your_jwt_token", "User Name" ); const participants = useSessionUsers(); if (isLoading) return
Joining session...
; if (isError) return
Error joining session
; return (
{isInSession && ( {participants.map(participant => ( ))} )}
); } ``` ## Available Hooks ### useSession Manages the complete lifecycle of a Zoom video session. ```tsx const { isInSession, isLoading, isError, error } = useSession( topic, // Session topic/ID token, // JWT authentication token userName, // Display name sessionPassword, // Optional session password sessionIdleTimeoutMins, // Optional idle timeout { disableVideo: false, disableAudio: false, language: "en-US", dependentAssets: "Global", waitBeforeJoining: 0, // Delay before auto-joining endSessionOnLeave: false, // End session when host leaves } ); ``` **Return values:** | Field | Type | Description | |-------|------|-------------| | `isInSession` | boolean | Currently in session | | `isLoading` | boolean | Session join in progress | | `isError` | boolean | Error occurred | | `error` | Error | Error object if any | ### useSessionUsers Provides real-time access to all session participants with reference stability. ```tsx const participants = useSessionUsers(); // participants is an array of Participant objects participants.map(p => (
{p.displayName} - {p.bVideoOn ? 'Video On' : 'Video Off'}
)); ``` ### useMyself Access the local user in the current session. ```tsx const myself = useMyself(); return (
{myself.userName} - {myself.bVideoOn ? 'Video On' : 'Video Off'}
); ``` ### useScreenShareUsers Get users who are currently sharing their screen. ```tsx const screenshareusers = useScreenShareUsers(); {screenshareusers.map(userId => ( ))} ``` ### useVideoState Manages video capture state and controls. ```tsx const { isVideoOn, toggleVideo, setVideo } = useVideoState(); // Toggle video on/off // Set video state explicitly ``` ### useAudioState Comprehensive audio state management. ```tsx const { isAudioMuted, isCapturingAudio, toggleMute, toggleCapture, setMute, setCapture } = useAudioState(); // Toggle mute // Toggle audio capture ``` ### useScreenshare Manages screen sharing functionality. ```tsx const { ScreenshareRef, startScreenshare } = useScreenshare(); return (
); ``` ## Components ### VideoPlayerContainerComponent **Required container** for video players. Must wrap all `VideoPlayerComponent` instances. ```tsx {participants.map(participant => ( ))} ``` ### VideoPlayerComponent Renders individual participant video streams. ```tsx const participants = useSessionUsers(); ``` ### ScreenShareContainerComponent **Required container** for screen share players. ```tsx {screenshareusers.map(userId => ( ))} ``` ### ScreenSharePlayerComponent Renders screen share streams. ```tsx ``` ## Complete Example ```tsx import React from 'react'; import { useSession, useSessionUsers, useMyself, useVideoState, useAudioState, useScreenshare, useScreenShareUsers, VideoPlayerComponent, VideoPlayerContainerComponent, ScreenSharePlayerComponent, ScreenShareContainerComponent, LocalScreenShareComponent } from '@zoom/videosdk-react'; interface VideoCallProps { topic: string; token: string; userName: string; } export const VideoCall: React.FC = ({ topic, token, userName }) => { // Session management const { isInSession, isLoading, isError, error } = useSession( topic, token, userName, undefined, // no password undefined, // default idle timeout { disableVideo: false, disableAudio: false, } ); // Participants const participants = useSessionUsers(); const myself = useMyself(); const screenshareUsers = useScreenShareUsers(); // Media controls const { isVideoOn, toggleVideo } = useVideoState(); const { isAudioMuted, isCapturingAudio, toggleMute, toggleCapture } = useAudioState(); const { ScreenshareRef, startScreenshare } = useScreenshare(); // Loading state if (isLoading) { return
Joining session...
; } // Error state if (isError) { return
Error: {error?.message}
; } // Not in session if (!isInSession) { return
Not in session
; } return (
{/* Video Grid */} {participants.map(participant => (
{participant.displayName}
))}
{/* Screen Share */} {screenshareUsers.length > 0 && ( {screenshareUsers.map(userId => ( ))} )} {/* Local Screen Share Preview */} {/* Controls */}
{/* Audio */} {!isCapturingAudio ? ( ) : ( )} {/* Video */} {/* Screen Share */}
{/* Participant Info */}

Logged in as: {myself?.userName}

Participants: {participants.length}

); }; ``` ## Interoperability with @zoom/videosdk The React SDK is designed to work alongside the core `@zoom/videosdk`. You can use both: ```tsx import ZoomVideo from '@zoom/videosdk'; import { useSession, useSessionUsers } from '@zoom/videosdk-react'; // Use React hooks for common patterns const { isInSession } = useSession(topic, token, userName); const participants = useSessionUsers(); // Access the underlying client for advanced features const client = ZoomVideo.createClient(); const chatClient = client.getChatClient(); const recordingClient = client.getRecordingClient(); ``` ## Project Structure ``` src/ ├── components/ # React components │ ├── VideoPlayerComponent │ ├── VideoPlayerContainerComponent │ ├── ScreenSharePlayerComponent │ ├── ScreenShareContainerComponent │ └── LocalScreenShareComponent ├── hooks/ # Custom React hooks │ ├── useSession │ ├── useSessionUsers │ ├── useMyself │ ├── useVideoState │ ├── useAudioState │ ├── useScreenshare │ └── useScreenShareUsers └── index.ts # Main exports ``` ## Key Benefits | Benefit | Description | |---------|-------------| | **Simplified State** | Automatic participant state management | | **Reference Stability** | Hooks maintain stable references | | **TypeScript Support** | Full type definitions included | | **Flexible** | Use alongside core SDK | | **Customizable** | Components accept standard React props | ## Official Repository - **GitHub**: [zoom/videosdk-react](https://github.com/zoom/videosdk-react) ## Related Documentation - [Session Join Pattern](session-join-pattern.md) - Manual SDK usage - [Video Rendering](video-rendering.md) - Manual attachVideo() patterns - [Event Handling](event-handling.md) - Event patterns