useAppUtils
useAppUtils hook allows you to set displayName
, avatarUrl
and sendData
.
You can import useAppUtils
hook from @huddle01/react/app-utils
Name | Type | |
---|---|---|
setDisplayName(displayName: string) | Function | Set the display name of the current user |
changeAvatarUrl(avatarUrl: string) | Function | Set the avatar url of the current user |
sendData(peerIds: [] | "*", data: unknown) | Function | Send data to the specified peerIds or all peers if '*' is passed as peerIds |
error | string | Error message occurs while using any function of useAppUtils hook |
displayName | string | Display name of the current user |
Example
import { useEffect } from "react";
import { Button, View } from 'react-native';
import { useAppUtils } from "@huddle01/react/app-utils";
const App = () => {
useEffect(() => {
if(changeAvatarUrl.isCallable) {
changeAvatarUrl("YOUR AVATAR URL")
}
}, [changeAvatarUrl.isCallable]);
useEffect(() => {
if(setDisplayName.isCallable) {
setDisplayName("YOUR DISPLAY NAME")
}
}, [setDisplayName.isCallable]);
const sendDataToAllPeers = () => {
sendData("*", { message: "Hello World" })
};
const sendDataToSpecificPeer = () => {
sendData(["PEER_ID"], { message: "Hello World" })
};
return (
<View>
<View style={styles.button}>
<Button
title="Send data to all peers"
onPress={sendDataToAllPeers}
/>
</View>
<View style={styles.button}>
<Button
title="Send data to specific peer"
onPress={sendDataToSpecificPeer}
/>
</View>
</View>
)
};