Skip to content

Commit

Permalink
[FCE-567]: Add docs about useReconnection hook (#16)
Browse files Browse the repository at this point in the history
## Description

- Added docs about `useReconnection` hook
  • Loading branch information
MiloszFilimowski authored Sep 23, 2024
1 parent 30725b7 commit 913dfbc
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions guide/react-native/reconnect.mdx
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/>;
}
```

0 comments on commit 913dfbc

Please sign in to comment.