Skip to content

Instantly share code, notes, and snippets.

@digitallysavvy
Last active January 9, 2024 02:52
Show Gist options
  • Save digitallysavvy/a55ec3957246bff5b4c20c0b5d3637fd to your computer and use it in GitHub Desktop.
Save digitallysavvy/a55ec3957246bff5b4c20c0b5d3637fd to your computer and use it in GitHub Desktop.
App.tsx for implementing the Agora RTC React SDK using routes.
import { Route, Routes, useNavigate } from 'react-router-dom'
import { ConnectForm } from './components/ConnectForm'
import { LiveVideo } from './components/LiveVideo'
import AgoraRTC, {
AgoraRTCProvider,
useRTCClient,
} from "agora-rtc-react";
import './App.css'
function App() {
const navigate = useNavigate()
const agoraClient = useRTCClient( AgoraRTC.createClient({ codec: "vp8", mode: "rtc" })); // Initialize Agora Client
const handleConnect = (channelName: string) => {
navigate(`/via/${channelName}`) // on form submit, navigate to new route
}
return (
<Routes>
<Route path='/' element={ <ConnectForm connectToVideo={ handleConnect } /> } />
<Route path='/via/:channelName' element={
<AgoraRTCProvider client={agoraClient}>
<LiveVideo />
</AgoraRTCProvider>
} />
</Routes>
)
}
export default App
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment