Skip to content

useChat messages array is empty after sending a message #132

@dancer

Description

@dancer

I set up useChat with the default api route but when I send a message the messages array stays empty. No errors in console.

"use client"
import { useChat } from "ai/react"

export default function Chat() {
  const { messages, input, handleSubmit, handleInputChange } = useChat()

  return (
    <div>
      {messages.map(m => <p key={m.id}>{m.content}</p>)}
      <form onSubmit={handleSubmit}>
        <input value={input} onChange={handleInputChange} />
      </form>
    </div>
  )
}

My api route just returns a basic text response. What format does the response need to be in? Do I need to use streamText?

ai@6.0.3, next.js 16

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions