Join our Discord Community

React AI Chatbot Interface

React AI chatbot with streaming responses and reasoning display. Complete ChatGPT-style interface with model selection, sources, and TypeScript support using shadcn/ui.

Building AI chat interfaces?

Join our Discord community for help from other developers.


Everyone's building AI chat now. Slap together a text input and div for messages, call it done. Then spend three weeks debugging why messages flicker during streaming, scroll jumps around, and users can't tell when the AI is thinking versus broken. This React component handles the annoying stuff—proper streaming states, scroll management, and all the UI details users expect from ChatGPT.

Loading component...

Built with TypeScript and shadcn/ui. Combines dedicated AI components for conversation display, message formatting, prompt input, and reasoning sections. The component handles streaming coordination, scroll management, and state updates so you can focus on connecting your AI API.

Why most AI chat UIs suck

Your basic chat implementation works fine until users start actually using it. Messages arrive character by character but the scroll jumps around. No visual feedback when the AI is thinking—users assume it's broken. The model dropdown conflicts with the input focus. Auto-scroll fights with manual scrolling. Trust me, I've debugged this exact combination at least five times.

This component handles the coordination nightmares: streaming without scroll jumping, typing indicators that don't break layout, model switching that doesn't lose focus, and proper loading states throughout. Plus reasoning sections and source citations because users expect transparency now, not just raw responses.

Built with accessibility in mind—screen readers work with streaming content, keyboard navigation doesn't break during updates, and touch targets are sized properly for mobile.

Installation

npx shadcn@latest add https://www.shadcn.io/registry/ai-chatbot.json
npx shadcn@latest add https://www.shadcn.io/registry/ai-chatbot.json
pnpm dlx shadcn@latest add https://www.shadcn.io/registry/ai-chatbot.json
bunx shadcn@latest add https://www.shadcn.io/registry/ai-chatbot.json

Usage

import {
  Conversation,
  ConversationContent,
  ConversationScrollButton,
} from '@repo/ai/conversation';
import { Message, MessageAvatar, MessageContent } from '@repo/ai/message';
import {
  PromptInput,
  PromptInputSubmit,
  PromptInputTextarea,
  PromptInputToolbar,
} from '@repo/ai/prompt-input';
import { Reasoning, ReasoningContent, ReasoningTrigger } from '@repo/ai/reasoning';
import { Sources, SourcesContent, SourcesTrigger } from '@repo/ai/sources';

const ChatInterface = () => {
  const [messages, setMessages] = useState([]);
  const [input, setInput] = useState('');
  const [isStreaming, setIsStreaming] = useState(false);

  return (
    <div className="flex h-full w-full flex-col">
      <Conversation className="flex-1">
        <ConversationContent>
          {messages.map((message) => (
            <Message key={message.id} from={message.role}>
              <MessageContent>{message.content}</MessageContent>
              <MessageAvatar src={message.avatar} name={message.name} />
            </Message>
          ))}
        </ConversationContent>
        <ConversationScrollButton />
      </Conversation>
      
      <PromptInput onSubmit={handleSubmit}>
        <PromptInputTextarea
          value={input}
          onChange={(e) => setInput(e.target.value)}
          placeholder="Ask me anything..."
        />
        <PromptInputToolbar>
          <PromptInputSubmit disabled={!input.trim()} />
        </PromptInputToolbar>
      </PromptInput>
    </div>
  );
};

Features

  • Streaming that doesn't break scroll - Messages appear character by character without jumping the viewport around
  • Smart auto-scroll management - Stays at bottom during streaming, lets users read history without fighting back
  • Model switching - Dropdown for GPT-4, Claude, Gemini, etc. with persistence and proper state coordination
  • Reasoning sections - Collapsible "thinking" display that auto-expands during AI reasoning, manual toggle after
  • Source citations - Expandable reference links with automatic counting ("Used 3 sources")
  • Proper loading states - Typing indicators, submit button states, and visual feedback throughout
  • TypeScript everywhere - Complete interfaces for messages, reasoning, sources, and streaming states
  • Touch-friendly mobile - 44px touch targets, virtual keyboard handling, responsive conversation layout
  • Keyboard shortcuts - Enter to send, Shift+Enter for newlines, Escape to cancel, Tab navigation
  • Copy-paste ready - Import the components, connect your API, done. No state management confusion
  • shadcn/ui integration - Uses existing design tokens and works with your theme customization
  • Screen reader friendly - ARIA live regions for streaming, proper focus management, reduced motion support

Use Cases

This free open source React component works perfectly for:

  • AI customer support - Interactive help systems with reasoning transparency and source attribution in Next.js applications
  • Development assistants - Code help chatbots with model selection and conversation management using TypeScript
  • Content creation tools - Writing assistants with streaming responses and multi-model support
  • Educational platforms - Learning chatbots with step-by-step reasoning display and source verification
  • Research interfaces - AI research tools with citation tracking and conversation organization
  • Documentation helpers - Interactive docs with AI guidance and contextual source linking
  • Product demos - Showcase AI capabilities with professional chat interfaces and model comparison
  • Enterprise applications - Internal AI tools with audit trails and reasoning transparency

API Reference

AIChatbot

The main chatbot interface component providing complete conversational AI functionality.

PropTypeDefaultDescription
messagesChatMessage[][]Array of conversation messages with metadata
onMessageSend(message: string) => void-Callback when user sends a message
isStreamingbooleanfalseWhether AI is currently responding
selectedModelstring-Currently selected AI model identifier
onModelChange(model: string) => void-Callback when user changes AI model
classNamestring-Additional CSS classes for container
...propsHTMLAttributes-All HTML div attributes supported

ChatMessage Interface

PropertyTypeDescription
idstringUnique message identifier
contentstringMessage text content
role'user' | 'assistant'Message sender role
timestampDateMessage creation time
reasoningstringOptional AI reasoning text
sourcesSource[]Optional citation sources
isStreamingbooleanWhether message is actively streaming

Conversation Management

The component automatically handles:

  • Message state with proper React state updates and re-rendering
  • Scroll behavior with auto-scroll to latest and manual scroll controls
  • Streaming coordination between input states and message display
  • Model persistence saving user preferences to localStorage

Streaming Specifications

ElementBehaviorAnimationAccessibility
Message contentCharacter-by-character display50ms intervalsScreen reader friendly
Reasoning sectionAuto-expand when completeSlide animationKeyboard navigable
Sources listAppear after messageFade inFocus management
Typing indicatorPulsing loaderContinuousARIA live region

Common gotchas

Message streaming performance: Character-by-character updates can cause React re-render performance issues with long messages. The component uses optimized state updates and memoization to handle this efficiently.

Conversation scroll management: Auto-scrolling during streaming can conflict with user manual scrolling. The component detects user scroll intent and temporarily disables auto-scroll until the user returns to bottom.

Model switching during streaming: Changing models while a message is streaming can cause state conflicts. The component properly cancels ongoing streams and resets state when model selection changes.

Accessibility with dynamic content: Screen readers struggle with rapidly changing content during streaming. The component uses ARIA live regions and proper focus management to ensure accessibility.

Mobile keyboard interactions: Virtual keyboards on mobile can disrupt conversation scrolling and input focus. The component handles viewport changes and maintains proper scroll positioning.

TypeScript message types: Strict typing for AI messages requires proper interface definitions. Ensure your message objects match the ChatMessage interface for full type safety.

Explore the components it's built with

This AI chatbot combines multiple specialized AI components from our collection:

Questions developers actually ask