npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@saigontechnology/react-firebase-chat

v1.0.0

Published

A comprehensive ReactJS Firebase Chat library with real-time messaging, user authentication, and modern UI components

Readme

React Firebase Chat

A comprehensive ReactJS chat library that works with or without authentication. Perfect for demos, testing, or production applications. Includes real-time messaging, cross-platform compatibility with React Native, and modern UI components.

🌟 Key Highlights

  • 🚀 No Authentication Required - Start chatting immediately with SimpleChat
  • 🔥 Firebase Integration - Optional real-time sync with React Native apps
  • 📱 Cross-Platform Compatible - Messages sync between web and mobile
  • 🎨 Modern UI - Beautiful, responsive design out of the box
  • 📦 TypeScript Ready - Full type safety and IntelliSense support

Overview

The react-firebase-chat library is designed to:

  • Share the same Firebase backend with React Native applications
  • Maintain data compatibility and synchronization across platforms
  • Provide similar API interface for easy adoption
  • Ensure real-time communication between web and mobile users

Timestamp behavior

This web library uses client-side timestamps (Date.now()) when writing to Firestore for fields like createdAt, updatedAt, latestMessageTime, and joinedAt. If you require server-side timestamps for stronger ordering guarantees across clients, you may change these to Firestore serverTimestamp() in your app.

Installation

From NPM (Recommended)

npm install @saigontechnology/react-firebase-chat firebase tailwindcss framer-motion
# or
yarn add @saigontechnology/react-firebase-chat firebase tailwindcss framer-motion

From GitHub

npm install git+https://github.com/saigontechnology/react-firebase-chat.git firebase tailwindcss framer-motion
# or
yarn add git+https://github.com/saigontechnology/react-firebase-chat.git firebase tailwindcss framer-motion

Note: When installing from GitHub, the package will automatically build the dist folder during installation thanks to the postinstall script.

Installing Dev Dependencies

npm install --save-dev autoprefixer postcss postcss-cli
# or
yarn add autoprefixer postcss postcss-cli --dev

Note: Our package is built with tailwindcss so if you did not init the project with it, you will have to configure for it before using this package.

🚀 Quick Start

Theme Notice

Add Material Icons on root head tag

  <html lang="en">
    <head>
      {/* Add Material Icons */}
      <link rel="preconnect" href="https://fonts.googleapis.com" />
      <link
        rel="preconnect"
        href="https://fonts.gstatic.com"
        crossOrigin="anonymous"
      />
      <link
        href="https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:opsz,wght,FILL,GRAD@24,400,0,0&display=swap"
        rel="stylesheet"
      />
      {/* Add Material Icons */}
    </head>
    <body>
      {children}
    </body>
  </html>

1. Initialize with ChatProvider

"use client";

import React from "react";
import {
  ChatScreen as BasicChatScreen,
  ChatProvider,
  IUser,
  initializeFirebase,
} from "react-firebase-chat";

const firebaseConfig = {
  apiKey: "your-web-api-key",
  authDomain: "your-project.firebaseapp.com",
  projectId: "your-project-id",
  storageBucket: "your-project.appspot.com",
  messagingSenderId: "123456789",
  appId: "your-app-id",
  measurementId: "your-measurement-id",
};

initializeFirebase(firebaseConfig);

export default function ChatRoutePage() {
  // Replace with your user information from your auth system
  const currentUser: IUser = {
    id: "your-user-id",
    name: "your-user-name",
    avatar: "your-user-avatar",
  };

  if (!currentUser) {
    return (
      <div style={{ padding: 24 }}>
        <p>Missing user information. Please go back to the login page.</p>
      </div>
    );
  }

  return (
    <div
      style={{
        height: "100vh",
        width: "100%",
        display: "flex",
        alignItems: "center",
        justifyContent: "center",
      }}
    >
      <div
        style={{
          height: 1000,
          width: 1000,
          display: "flex",
          flexDirection: "column",
        }}
      >
        <ChatProvider currentUser={currentUser}>
          <BasicChatScreen partners={[]} showFileUpload={true} />
        </ChatProvider>
      </div>
    </div>
  );
}

Note: You can check our Auth example for a basic UserService usage on Auth Example.

Authentication

This library does not include auth utilities. Provide your own auth and pass currentUser to ChatProvider.

Configuration

Configure the chat behavior with the ChatProvider:

<ChatProvider
  currentUser={currentUser}
  firebaseConfig={firebaseConfig}
  encryptionKey="optional-encryption-key"
>
  <App />
</ChatProvider>

Available Hooks

import { useChat, useMessages, useTyping, useChatContext } from 'react-firebase-chat';

// Main chat functionality
const { messages, sendMessage, loading, error } = useChat({
  user: currentUser,
  conversationId: 'conversation-123'
});

// Message pagination
const { messages, loadMore, hasMore } = useMessages('conversation-123');

// Typing indicators
const { typingUsers, setTyping } = useTyping('conversation-123', currentUser.id);

// Chat context
const { currentUser, isInitialized } = useChatContext();

Direct Service Usage

For advanced use cases, you can use services directly:

import { ChatService, UserService, initializeFirebase } from 'react-firebase-chat';

// Initialize Firebase
initializeFirebase(firebaseConfig);

// Get service instances
const chatService = ChatService.getInstance();
const userService = UserService.getInstance();

// Create users
await userService.createUserIfNotExists('user1', { name: 'Alice' });
await userService.createUserIfNotExists('user2', { name: 'Bob' });

// Create conversation
const conversationId = await chatService.createConversation(
  ['user1', 'user2'],
  'user1',
  'private'
);

// Send message
await chatService.sendMessage(conversationId, {
  text: 'Hello Bob!',
  type: MediaType.text,
  senderId: 'user1',
  readBy: { user1: true },
  path: '',
  extension: ''
});

// Subscribe to real-time messages
const unsubscribe = chatService.subscribeToMessages(
  conversationId,
  (messages) => {
    console.log('New messages:', messages);
  }
);

Services

The library provides three main services for advanced functionality:

ChatService

Handles all chat operations including conversations, messages, and real-time subscriptions.

import { ChatService } from 'react-firebase-chat';

const chatService = ChatService.getInstance();

// Create conversation
const conversationId = await chatService.createConversation(
  ['user1', 'user2'], 
  'initiatorId', 
  'private'
);

// Send message
await chatService.sendMessage(conversationId, messageData);

// Subscribe to real-time messages
const unsubscribe = chatService.subscribeToMessages(
  conversationId, 
  (messages) => setMessages(messages)
);

UserService

Manages user documents and profiles.

import { UserService } from 'react-firebase-chat';

const userService = UserService.getInstance();

// Create user if not exists
await userService.createUserIfNotExists('user123', {
  name: 'John Doe',
  avatar: 'https://example.com/avatar.jpg'
});

// Get all users
const users = await userService.getAllUsers();

FirebaseService

Handles Firebase initialization and provides access to Firebase services.

import { initializeFirebase, getFirebaseFirestore } from 'react-firebase-chat';

// Initialize Firebase
initializeFirebase(firebaseConfig);

// Get Firestore instance
const db = getFirebaseFirestore();

📖 For detailed service documentation, see SERVICES.md

Components

ChatScreen

Main chat interface component with three sections: app header, conversation sidebar, and chat panel. Selecting a conversation shows a loader only in the chat panel, not the whole screen.

Props:

  • conversationId?: string - Optional preselected conversation id
  • partners?: Array<{id: string, name: string, avatar?: string}> - Optional partners (for direct usage without sidebar)
  • memberIds: string[] - Member user IDs (optional when using sidebar-driven conversations)
  • style?: React.CSSProperties - Inline styles
  • className?: string - Additional CSS classes
  • onSend?: (messages: Message[]) => void - Optional callback when messages are sent
  • showCamera?: boolean - Enable camera functionality (default: true)
  • showFileUpload?: boolean - Enable file upload (default: true)
  • isGroup?: boolean - Whether this is a group chat (default: false)

Sidebar behavior:

  • Lists conversations from users/{userId}/conversations with name, latest message, unread badge and online dot placeholder
  • “New” button opens a modal with incremental search (top 3 matches from UserService after typing). Selecting a user creates a new conversation and opens it.

MessageList

Display list of messages.

Props:

  • messages: Message[] - Array of messages to display
  • currentUser: IUser - Current user for ownership detection
  • onMessageUpdate?: (message: Message) => void - Message edit handler
  • onMessageDelete?: (messageId: string) => void - Message delete handler
  • className?: string - Additional CSS classes

MessageInput

Text input for composing messages.

The input now relies on its container for styling and no longer enforces maxLength internally.

Props:

  • onSendMessage: (text: string) => void - Send message handler
  • onTyping?: (isTyping: boolean) => void - Typing indicator handler
  • disabled?: boolean - Disable input
  • placeholder?: string - Input placeholder text
  • className?: string - Additional CSS classes

UserAvatar

User profile picture with online status.

Props:

  • user: IUser - User data
  • size?: 'small' | 'medium' | 'large' - Avatar size
  • showOnlineStatus?: boolean - Show online indicator
  • className?: string - Additional CSS classes

ConnectionStatus

Network connection status indicator.

Props:

  • status: ConnectionStatus - Connection status ('connected' | 'connecting' | 'disconnected' | 'error')
  • className?: string - Additional CSS classes

TypingIndicator

Shows when users are typing.

Props:

  • typingUsers: TypingUser[] - Array of users currently typing
  • className?: string - Additional CSS classes

Firebase Setup

Firestore Rules

rules_version = '2';
service cloud.firestore {
  match /databases/{database}/documents {
    // Users can read/write their own profile
    match /users/{userId} {
      allow read, write: if request.auth != null && request.auth.uid == userId;
    }
    
    // Chat rooms - users can read rooms they're part of
    match /chatRooms/{roomId} {
      allow read, write: if request.auth != null && 
        request.auth.uid in resource.data.participants;
      
      // Messages within chat rooms
      match /messages/{messageId} {
        allow read, create: if request.auth != null && 
          request.auth.uid in get(/databases/$(database)/documents/chatRooms/$(roomId)).data.participants;
        allow update, delete: if request.auth != null && 
          request.auth.uid == resource.data.userId;
      }
      
      // Typing indicators
      match /typing/{userId} {
        allow read, write: if request.auth != null;
      }
    }
  }
}

Storage Rules

rules_version = '2';
service firebase.storage {
  match /b/{bucket}/o {
    match /chat/{roomId}/{allPaths=**} {
      allow read, write: if request.auth != null;
    }
  }
}

TypeScript

The library is built with TypeScript and provides full type definitions:

import type { 
  IUser, 
  IMessage, 
  IConversation,
  Message,
  TypingUser,
  ConnectionStatus,
  FirebaseConfig,
  UseChatProps,
  UseChatReturn
} from 'react-firebase-chat';

Contributing

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

License

MIT © [Your Name]

📚 Documentation