realtime presence firebase react native
import React, { useEffect } from 'react';
import auth from '@react-native-firebase/auth';
import database from '@react-native-firebase/database';
function App() {
useEffect(() => {
// Assuming user is logged in
const userId = auth().currentUser.uid;
const reference = database().ref(`/online/${userId}`);
// Set the /users/:userId value to true
reference.set(true).then(() => console.log('Online presence set'));
// Remove the node whenever the client disconnects
reference
.onDisconnect()
.remove()
.then(() => console.log('On disconnect function configured.'));
}, []);
}