-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FCE-567]: Add docs about useReconnection hook (#16)
## Description - Added docs about `useReconnection` hook
- Loading branch information
1 parent
30725b7
commit 913dfbc
Showing
1 changed file
with
36 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
--- | ||
sidebar_position: 7 | ||
--- | ||
|
||
# Reconnect | ||
|
||
If your connection is lost while you are connected to a room, the app will automatically handle the reconnection process. You can monitor these events by utilizing the `useReconnection` hook. | ||
|
||
### Example code that logs the current status to the console: | ||
|
||
```ts | ||
import { useEffect, useRef } from "react"; | ||
import { | ||
ReconnectionStatus, | ||
useReconnection, | ||
} from "@fishjam-cloud/react-native-client"; | ||
|
||
function Component() { | ||
const prevStatus = useRef<ReconnectionStatus>("idle"); | ||
const { reconnectionStatus } = useReconnection(); | ||
|
||
useEffect(() => { | ||
if (prevStatus.current == reconnectionStatus) return; | ||
prevStatus.current = reconnectionStatus; | ||
if (reconnectionStatus == "error") { | ||
console.log("Failed to reconnect"); | ||
} else if (reconnectionStatus == "reconnecting") { | ||
console.log("Connection is broken, reconnecting..."); | ||
} else { | ||
console.log("Connected succesfully"); | ||
} | ||
}, [reconnectionStatus]); | ||
|
||
return <View/>; | ||
} | ||
``` |