Make your AI a shadcn expert

Shadcn TanStack AI

React TanStack AI helper for scripted chat previews and tests. Built with TypeScript and Tailwind CSS for Next.js using @shadcn/helpers — stream useChat with no model.

createChat writes a conversation in code and replays it through TanStack AI's useChat as AG-UI events. No model, no route, no API key. Text and reasoning stream word by word. Tool calls move from input to result.

Scroll to load preview...

Usage

import { createChat } from "@shadcn/helpers/tanstack-ai"
import { useChat } from "@tanstack/ai-react"
const chat = createChat()
  .user("What changed in this release?")
  .assistant("Keyboard shortcuts and faster search.")

const { messages, append, status } = useChat({
  initialMessages: chat.get(0),
  connection: chat.transport(),
})

const next = chat.next(messages)
void append(next)

get(0) starts empty. append(next) adds the next scripted user turn. transport() is a local connection, not a server.

Composition

user
assistant
sleep
get
next
transport

Install @shadcn/helpers. Import from @shadcn/helpers/tanstack-ai. Keep @tanstack/ai-react as you already have it.

User Messages

user() adds a user turn. Pass id, or createdAt on metadata, as the second argument.

chat.user("What changed in this release?", {
  id: "user-release-question",
  metadata: { createdAt: "2026-01-01T10:00:00.000Z" },
})

Assistant Messages

A string is one text part. An array can mix thinking and text. Use a writer when the turn should stream in steps.

chat.assistant(({ writer }) => {
  writer.reasoning("I should summarize the release.")
  writer.text("Keyboard shortcuts and faster search.")
})

API

Prop

Type

Chat

Prop

Type

useChat is still @tanstack/ai-react. This helper only supplies the messages and the connection.

Notes

This is not a model

The stream is the script. Production chat still needs a real connection. Use this for previews, docs, and tests.

Need the AI SDK hook instead? See AI SDK.

With other components

Questions

Was this page helpful?

Sign in to leave feedback.