This guide helps AI assistants provide accurate integration instructions when users ask to "integrate stream-chat-react" or similar vague commands.
When a user wants to integrate stream-chat-react, follow this standard pattern:
npm install stream-chat stream-chat-react
# or
yarn add stream-chat stream-chat-reactBefore setting up the chat client, you'll need:
- API Key: Get your API key from the Stream Dashboard
- User Token: For development purposes, you can generate a user token manually using the Token Generator
- Note: Manual token generation is for development/testing only. For production, generate tokens server-side using your Stream API secret.
The minimal integration requires:
- Stream Chat client setup
- Chat component wrapper
- Channel component with basic UI
import { Chat, useCreateChatClient } from 'stream-chat-react';
import 'stream-chat-react/dist/css/v2/index.css';
// Get your API key from: https://dashboard.getstream.io/
// For development, generate a token at: https://getstream.io/chat/docs/php/tokens_and_authentication/#manually-generating-tokens
const apiKey = 'YOUR_API_KEY';
const userId = 'YOUR_USER_ID';
const userName = 'YOUR_USER_NAME';
const userToken = 'YOUR_USER_TOKEN';
const App = () => {
const client = useCreateChatClient({
apiKey,
tokenOrProvider: userToken,
userData: { id: userId, name: userName },
});
if (!client) return <div>Setting up client & connection...</div>;
return <Chat client={client}>Chat with client is ready!</Chat>;
};For a full-featured chat interface:
import type { ChannelFilters, ChannelOptions, ChannelSort, User } from 'stream-chat';
import {
Chat,
Channel,
ChannelHeader,
ChannelList,
MessageInput,
MessageList,
Thread,
Window,
useCreateChatClient,
} from 'stream-chat-react';
import 'stream-chat-react/dist/css/v2/index.css';
// Get your API key from: https://dashboard.getstream.io/
// For development, generate a token at: https://getstream.io/chat/docs/php/tokens_and_authentication/#manually-generating-tokens
const apiKey = 'YOUR_API_KEY';
const userId = 'YOUR_USER_ID';
const userName = 'YOUR_USER_NAME';
const userToken = 'YOUR_USER_TOKEN';
const user: User = {
id: userId,
name: userName,
image: `https://getstream.io/random_png/?name=${userName}`,
};
const sort: ChannelSort = { last_message_at: -1 };
const filters: ChannelFilters = {
type: 'messaging',
members: { $in: [userId] },
};
const options: ChannelOptions = {
limit: 10,
};
const App = () => {
const client = useCreateChatClient({
apiKey,
tokenOrProvider: userToken,
userData: user,
});
if (!client) return <div>Setting up client & connection...</div>;
return (
<Chat client={client}>
<ChannelList filters={filters} sort={sort} options={options} />
<Channel>
<Window>
<ChannelHeader />
<MessageList />
<MessageInput />
</Window>
<Thread />
</Channel>
</Chat>
);
};User intent: "Add stream-chat-react to my React app"
Steps:
- Install packages:
npm install stream-chat stream-chat-react - Get credentials:
- API key from Stream Dashboard
- User token (for development): Generate at Token Generator
- Import CSS:
import 'stream-chat-react/dist/css/v2/index.css' - Set up client using
useCreateChatClienthook - Wrap app with
<Chat>component - Add
<Channel>with<Window>,<MessageList>,<MessageInput>
Reference: See examples/tutorial/ for step-by-step examples
User intent: "Integrate chat into my existing React application"
Steps:
- Install packages
- Get credentials:
- API key from Stream Dashboard
- User token (for development): Generate at Token Generator
- Import CSS (preferably in a CSS layer for proper override precedence)
- Create a separate chat component or route
- Initialize client once at app level (use
useCreateChatClientonly once) - Access client elsewhere using
useChatContext()hook
Important: The client should be created once and reused. Don't create multiple clients.
User intent: "Customize the chat appearance"
Steps:
- Import Stream CSS into a CSS layer
- Create custom theme using CSS variables
- Apply theme via
themeprop on<Chat>component
@layer base, theme;
@import 'stream-chat-react/dist/css/v2/index.css' layer(base);
@layer theme {
.str-chat__theme-custom {
--str-chat__primary-color: #009688;
--str-chat__surface-color: #f5f5f5;
/* ... more variables */
}
}<Chat client={client} theme='str-chat__theme-custom'>
{/* ... */}
</Chat>Reference: See theming documentation and examples/vite/src/stream-imports-theme.scss
User intent: "Customize message or channel preview appearance"
Steps:
- Create custom component matching the prop interface
- Pass custom component via props (e.g.,
Message,ChannelPreview,Attachment) - Use hooks like
useMessageContext()to access data
const CustomMessage = () => {
const { message } = useMessageContext();
return (
<div>
{message.user?.name}: {message.text}
</div>
);
};
<Channel Message={CustomMessage}>{/* ... */}</Channel>;Reference: See examples/tutorial/src/4-custom-ui-components/
User intent: "Create a livestream-style chat"
Steps:
- Use
livestreamchannel type (disables typing indicators, read receipts) - Use
VirtualizedMessageListinstead ofMessageListfor performance - Apply dark theme:
theme="str-chat__theme-dark" - Set
liveprop onChannelHeader
<Chat client={client} theme='str-chat__theme-dark'>
<Channel channel={channel}>
<Window>
<ChannelHeader live />
<VirtualizedMessageList />
<MessageInput focus />
</Window>
</Channel>
</Chat>Reference: See examples/tutorial/src/7-livestream/
User intent: "Add emoji picker and autocomplete"
Emoji support is built into the SDK β the StreamEmojiPicker needs no emoji-mart
packages or init() call.
Deprecation: the
EmojiPickerexport fromstream-chat-react/emojisis the legacy emoji-mart-backed picker. It still works unchanged for backwards compatibility, but is deprecated and will be removed in v15 and logs a one-time console warning. New integrations should useStreamEmojiPicker; existing emoji-mart integrations keep working until you migrate (see Migrating from emoji-mart below).
Steps:
- Import
StreamEmojiPickerfromstream-chat-react/emojisand pass it toChannel. - Import the emoji picker's stylesheet:
import 'stream-chat-react/css/emoji-picker.css'. It is intentionally not part ofindex.css(so apps that don't use the picker ship no emoji CSS); without it the picker panel renders unstyled. - (Optional) For
:shortcodeautocomplete + emoticon replacement, register the emoji middleware on the message composer's text composer withcreateTextComposerEmojiMiddleware()(no argument β it uses the built-in index).
import { StreamEmojiPicker } from 'stream-chat-react/emojis';
import 'stream-chat-react/css/emoji-picker.css';
<Channel EmojiPicker={StreamEmojiPicker}>{/* ... */}</Channel>;Notes:
-
Passing a custom
emojiSearchIndex(including emoji-mart'sSearchIndex) is still supported for advanced use. -
On
StreamEmojiPicker, skin tone and "frequently used" are integrator-managed props (skinTone/onSkinToneChange,frequentlyUsedEmoji/onFrequentlyUsedChange); the SDK does not persist them. Seeexamples/vite/for a localStorage example. -
On
StreamEmojiPicker,pickerPropsaccepts a curated set of emoji-mart-compatiblePickeroptions (plusthemeandstyle):- Layout:
navPosition/previewPosition('top' | 'bottom' | 'none'),searchPosition('sticky' | 'static' | 'none'),skinTonePosition('preview' | 'search' | 'none'). - Grid & content:
perLine(default9),categories(filter + reorder;'frequent'always prepends),maxFrequentRows(default1). - Filtering & polish:
exceptEmojis,emojiVersion,noCountryFlags,previewEmoji,noResultsEmoji,autoFocus,onClickOutside.
Divergences from emoji-mart's defaults:
autoFocusdefaults totrue;emojiVersionis unfiltered by default (the bundled set 15);previewEmoji/noResultsEmojidefault to the SDK's placeholder / empty state;noCountryFlagsis opt-in (no Windows auto-detect);categoriescannot reposition'frequent'.Not supported (rejected by the type; ignored with a console warning at runtime): image sets (
set,getSpritesheetURL),customemoji,data,i18n/locale,dynamicWidth,icons,categoryIcons. Sizing knobs (emojiSize,emojiButtonSize, β¦) are--str-chat__emoji-picker-*CSS variables, not props. Skin tone uses the first-classskinTone/defaultSkinToneprops (not emoji-mart'sskin). Try these live in the "Emoji Picker" settings tab ofexamples/vite/. - Layout:
-
To let users react with any emoji (the reaction selector's
+button), fillreactionOptions.extendedwith the full emoji set. It also gates display β a reaction whose type isn't inquick/extendedis not rendered. Load it lazily from the emojis entry (the dataset is code-split, so this adds nothing to your initial bundle):import { defaultReactionOptions, type ReactionOptions } from 'stream-chat-react'; import { loadDefaultExtendedReactionOptions } from 'stream-chat-react/emojis'; const [reactionOptions, setReactionOptions] = useState<ReactionOptions>(defaultReactionOptions); useEffect(() => { loadDefaultExtendedReactionOptions().then((extended) => setReactionOptions({ ...defaultReactionOptions, extended }), ); }, []); <Channel reactionOptions={reactionOptions}>{/* ... */}</Channel>;
For a curated subset instead, build the
extendedmap yourself withmapEmojiMartData. -
Migrating from emoji-mart (the deprecated
EmojiPicker): swapEmojiPickerβStreamEmojiPicker, then remove theemoji-mart/@emoji-mart/react/@emoji-mart/datainstalls and anyinit({ data })call. The deprecatedEmojiPickerstill accepts raw emoji-martpickerProps(e.g.set,emojiSize);StreamEmojiPickeruses the curatedpickerPropsabove. Autocomplete (createTextComposerEmojiMiddleware) and reactions (mapEmojiMartData) are engine-agnostic and need no changes.
Reference: See examples/tutorial/src/6-emoji-picker/
For custom properties on channels, messages, attachments, etc., create a declaration file:
// stream-chat.d.ts
import { DefaultChannelData, DefaultAttachmentData } from 'stream-chat-react';
declare module 'stream-chat' {
interface CustomChannelData extends DefaultChannelData {
image?: string;
name?: string;
}
interface CustomAttachmentData extends DefaultAttachmentData {
image?: string;
name?: string;
url?: string;
}
}Basic layout CSS for proper component positioning:
html,
body,
#root {
height: 100%;
}
body {
margin: 0;
}
#root {
display: flex;
}
.str-chat__channel-list {
width: 30%;
}
.str-chat__channel {
width: 100%;
}
.str-chat__thread {
width: 45%;
}<Chat>- Root provider, wraps entire chat app<Channel>- Channel context provider<ChannelList>- Displays list of channels<MessageList>- Displays messages in channel<MessageInput>- Input for sending messages<Thread>- Thread/reply view<Window>- Wrapper for channel UI<VirtualizedMessageList>- Virtualized message list for high volume
<ChannelHeader>- Channel header with info<Attachment>- Renders message attachments
useCreateChatClient()- Creates and connects client (use once per app)useChatContext()- Access client instanceuseMessageContext()- Access current message datauseChannelContext()- Access current channel data
Solution: Ensure useCreateChatClient returns a client before rendering <Chat>. Show loading state while client is null.
Solution:
- Import CSS:
import 'stream-chat-react/dist/css/v2/index.css' - Use CSS layers for proper override precedence
- Check CSS import order
Solution: Use useCreateChatClient only once at app root. Use useChatContext() to access client elsewhere.
Solution: Create stream-chat.d.ts file with proper type declarations (see TypeScript Setup section).
Solution:
- Ensure
EmojiPickerfromstream-chat-react/emojisis passed toChannel(or set viaComponentContext) - Import the emoji picker CSS:
import 'stream-chat-react/css/emoji-picker.css' - For
:shortcodeautocomplete, registercreateTextComposerEmojiMiddleware()on the composer's text composer
- Official Tutorial: https://getstream.io/chat/react-chat/tutorial/
- Tutorial Source: https://raw.githubusercontent.com/GetStream/getstream.io-tutorials/refs/heads/main/chat/tutorials/react-tutorial.mdx
- Component Docs: https://getstream.io/chat/docs/sdk/react/
- Examples in Repo:
examples/tutorial/(step-by-step),examples/vite/(complete example) - API Docs: https://getstream.io/chat/docs/javascript/
- Get API Key: https://dashboard.getstream.io/
- Token Generator (Development): https://getstream.io/chat/docs/php/tokens_and_authentication/#manually-generating-tokens
- Package Name:
stream-chat-react - Peer Dependencies:
react: ^19.0.0 || ^18.0.0 || ^17.0.0react-dom: ^19.0.0 || ^18.0.0 || ^17.0.0stream-chat: ^9.27.2
- Emoji support: built in via the
stream-chat-react/emojisentry point β noemoji-martpackages required.
- Client Creation: Create client once at app root, reuse via context
- CSS Layers: Use CSS layers for proper style override precedence
- Loading States: Always check if client is ready before rendering chat components
- Type Safety: Use TypeScript declaration files for custom properties
- Performance: Use
VirtualizedMessageListfor high message volume scenarios - Theming: Use CSS variables and theme classes rather than direct CSS overrides
- Credentials: Never hardcode credentials in production; use environment variables
When helping users integrate, ensure:
- Packages installed (
stream-chat,stream-chat-react) - API key obtained from Stream Dashboard
- User token generated (for development: use Token Generator)
- CSS imported (
stream-chat-react/dist/css/v2/index.css) - Client created with
useCreateChatClient(once, at app root) - Loading state handled (check
if (!client)) -
<Chat>component wraps chat UI - At minimum:
<Channel>with<Window>,<MessageList>,<MessageInput> - Layout CSS added if needed (for proper positioning)
- TypeScript declarations added if using custom properties
- Theme applied if customizing appearance
- Credentials properly configured (API key, user token, etc.)
Note for AI Assistants: When users ask vague questions like "integrate stream-chat-react", start with the Quick Start Integration Pattern above. Ask clarifying questions about their use case (new app vs existing, styling needs, features required) to provide the most relevant scenario from Common Integration Scenarios.