RefirebaseRefirebase

useValue

Subscribe to a Realtime Database path with real-time updates.

Usage

The useValue hook listens to a specific path in the Firebase Realtime Database and updates automatically when data changes.

React Component
import { useValue } from 'refirebase/react';

function Status() {
  const { data: status, loading, error } = useValue('system/status');

  if (loading) return <p>Loading...</p>;
  if (error) return <p>Error loading status.</p>;
  
  return <div>System status: {status}</div>;
}

Parameters

ParamTypeDescription
path*stringThe Realtime Database path to subscribe to.

Return value

Returns

{ data: T | null, loading: boolean, error: unknown | null }

An object containing the path data, loading state, and any error.