The parameters or asynchronous function required to join the channel. See JoinOptions
for details.
Whether the user is ready to join the channel. The default value is true
.
Optional
client: null | IAgoraRTCClientCreated using the Web SDK's IAgoraRTC.createClient
method.
import { useJoin } from "agora-rtc-react";
function App() {
// Example: passing a function as first argument
// useJoin(async () => {
// Fetch the token before joining the channel. Note that the data type of getData must be fetchArgs
// const getData = await getToken();
// return getData;
// }, calling);
useJoin(
{
appid: YOUR_APPID,
channel: YOUR_CHANNEL,
token: YOUR_TOKEN,
},
ready,
);
return <></>;
}
This hook lets a user automatically join a channel when the component is ready and automatically leaves the channel when the component is unmounted. You can customize the conditions required to join a channel using fetchArgs. For example, generating a token and other asynchronous operations can be performed before joining the channel.