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 🙏

© 2025 – Pkg Stats / Ryan Hefner

react-chat-component-tr

v1.0.16

Published

A customizable React chat component with emoji support and message delivery status

Readme

React Chat Component TR

A fully customizable and socket-enabled React chat component with emoji support, message delivery statuses, typing indicators, and theming.

✨ Features

  • 💬 Real-time chat interface using socket.io
  • 🎨 Customizable theming
  • 📦 Message delivery status (sending, sent, delivered, error)
  • 🌐 Typing indicator
  • 😀 Emoji support
  • 🌓 Dark/light mode toggle
  • 📱 Responsive design
  • ⚡ Built-in TypeScript support
  • 🔌 Easily integrates with any socket backend

📦 Installation

npm install react-chat-component-tr
# or
yarn add react-chat-component-tr

🧩 Types

ChatMessage

type ChatMessage = {
  id: string;
  senderId: string;
  content: string;
  timestamp: string | Date;
  status?: 'sending' | 'sent' | 'delivered' | 'error';
};

ChatTheme

type ChatTheme = {
  primaryColor?: string;
  secondaryColor?: string;
  backgroundColor?: string;
  textColor?: string;
  messageBubbleColor?: string;
  ownMessageBubbleColor?: string;
  ownMessageTextColor?: string;
  timestampColor?: string;
  statusColor?: string;
};

🚀 Usage

import { useState } from 'react';
import io from 'socket.io-client';
import {Chat, type ChatMessage} from 'react-chat-component-tr';

const socket = io('http://localhost:3000'); // your socket backend URL

const ChatComponent = () => {
  const initialMessages: ChatMessage[] = [ { id: '1', senderId: 'user-456', content: 'Hello there!', timestamp: new Date() ,status:'sending' },
  ]
  const [messages, setMessages] = useState<ChatMessage[]>(initialMessages);

  return (
    <Chat
      userId="user123"
      socket={socket}
      messagesList={messages}
      setMessagesList={setMessages}
      showTypingIndicator={true}
      showDeliveryStatus={true}
      placeholder="Type your message..."
    />
  );
};

export default ChatComponent;

🧠 Props

| Prop | Type | Required | Default | Description | |--------------------|-------------------------------------------|----------|--------------|-------------| | userId | string | ✅ | — | The ID of the current user | | socket | SocketIOClient.Socket | ✅ | — | Connected socket instance | | messagesList | ChatMessage[] | ✅ | — | Current list of messages | | setMessagesList | Dispatch<SetStateAction<ChatMessage[]>> | ✅ | — | State updater function for messages | | onMessageSent | (message: ChatMessage) => void | ❌ | — | Callback after sending a message | | initialMessages | ChatMessage[] | ❌ | [] | Initial messages (used only if messagesList is not set) | | theme | ChatTheme | ❌ | default | Theme customization | | placeholder | string | ❌ | "Type a message..." | Placeholder text for input | | disabled | boolean | ❌ | false | Disable input field | | showTypingIndicator | boolean | ❌ | true | Show typing indicator | | showDeliveryStatus | boolean | ❌ | true | Show message delivery status |


📡 Socket Events

Make sure your backend socket emits and listens to the following events:

Emitted by Frontend

  • 'message': Sends a new message
  • 'typing': Notifies that the user is typing

Listened by Frontend

  • 'message': Receives new incoming messages
  • 'typing': Receives typing indicator updates
  • 'messageStatusUpdate': Receives message status changes (sent, delivered, etc.)

🎨 Theming Example

const theme = {
  primaryColor: '#1976d2',
  secondaryColor: '#dc004e',
  backgroundColor: '#ffffff',
  textColor: '#000000',
  messageBubbleColor: '#e0e0e0',
  ownMessageBubbleColor: '#1976d2',
  ownMessageTextColor: '#ffffff',
  timestampColor: '#888888',
  statusColor: '#4caf50'
};

🌓 Mode Switch

A built-in toggle (<ModeSwitch />) is included in the UI to demonstrate dark/light themes if you wrap your app in a compatible theme context.


📜 License

MIT — free to use, modify, and distribute.


🙌 Contributing

PRs and issues are welcome. Let's build an awesome chat system together!


📬 Example Socket.io Server (Node.js)

import { Server } from 'socket.io';

const io = new Server(3000, {
  cors: {
    origin: '*',
  },
});

io.on('connection', (socket) => {
  socket.on('message', (msg, ack) => {
    // simulate status change to 'delivered'
    setTimeout(() => {
      io.emit('messageStatusUpdate', { id: msg.id, status: 'delivered' });
    }, 1000);

    io.emit('message', msg);
    ack?.();
  });

  socket.on('typing', ({ senderId }) => {
    socket.broadcast.emit('typing', { senderId });
  });
});