Skip to main content

Overview

Manages the typing indicator for a conversation. Returns the list of user IDs currently typing (for rendering a “Someone is typing…” indicator) and startTyping/stopTyping functions that emit the appropriate socket events.
Requires ChatProvider in the component tree.

Usage Example

Props

string
required
The ID of the conversation to track typing state for.

Returns

string[]
Array of user IDs currently typing in this conversation. The current user is always excluded.
() => void
Emits a typing:start event to the server. Throttled internally — safe to call on every keystroke. Re-emits the keep-alive every 2 seconds while typing continues.
() => void
Emits a typing:stop event to the server and cancels the keep-alive interval. Call on message send, input clear, or blur.

Notes

  • startTyping() is idempotent while already typing — calling it repeatedly does not emit duplicate events; only the keep-alive timer re-emits every 2 seconds.
  • On unmount, if the user was typing, typing:stop is emitted automatically to prevent a stale indicator on recipients’ screens.
  • Each typing user is auto-removed from typingUsers after 5 seconds of no keep-alive (handled by ChatProvider).
  • In a direct (1:1) conversation frozen by a block, the server relays neither person’s typing to the other, so the other person doesn’t appear in typingUsers there (one already showing when the block lands clears after the usual 5 seconds).
  • For integration guidance, see Chat: Real-time.