Overview
TheuseChatSimulator hook automatically generates simulated incoming messages at regular intervals to demonstrate chat functionality. It shows typing indicators before messages appear and randomly sends either text or media messages.
Usage
This hook is designed for demo and preview environments. It should not be used in production applications with real chat data.
Signature
Return value
This hook does not return any value. It manages side effects internally.Behavior
The hook performs the following actions:- Message generation interval: Every 18 seconds, picks a random chat and contact
- Typing indicator: Shows the contact is typing for 2.2-4 seconds
- Message type: 75% chance of text message, 25% chance of media message
- Cleanup: Clears all intervals and timers when the component unmounts
Text messages
Randomly selects from these response snippets:- “Just synced the latest updates – take a look when you can.”
- “Love where this is headed!”
- “I’ll package these assets and drop them in a bit.”
- “Can we align on the microcopy before handoff?”
- “Here’s a quick mock to illustrate the interaction.”
Media messages
Sends image messages with sample URLs and captions from a predefined set of design-related content.Dependencies
This hook relies on the chat store from@/lib/chat/state and uses the following store methods:
Contact data from the chat store
Active chats from the chat store
Function to add a new message to a chat
Function to show/hide typing indicators
Implementation details
The hook automatically cleans up all timers and intervals when the component unmounts to prevent memory leaks.
Source
See the full implementation inhooks/use-chat-simulator.ts:32