RefirebaseRefirebase

useUser

Hook to access the current authenticated Firebase user.

Usage

Use this hook to get the currently authenticated user in real-time. It listens to state changes and avoids boilerplate onAuthStateChanged listeners.

UserProfile.tsx
import { useUser } from 'refirebase/react';

export function UserProfile() {
  const { user, loading } = useUser();

  if (loading) return <div>Loading...</div>;
  if (!user) return <div>Please sign in</div>;

  return <div>Welcome, {user.displayName}!</div>;
}

Return value

Returns

{ user: User | null, loading: boolean }

The current user object and a loading state.