Answers for "realtime presence firebase react native"

0

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.'));
  }, []);
}
Posted by: Guest on October-08-2021

Code answers related to "realtime presence firebase react native"

Code answers related to "Javascript"

Browse Popular Code Answers by Language