diff --git a/content/docs/02-getting-started/02-nextjs-app-router.mdx b/content/docs/02-getting-started/02-nextjs-app-router.mdx index c419cebb5ffc..4d961bca74e9 100644 --- a/content/docs/02-getting-started/02-nextjs-app-router.mdx +++ b/content/docs/02-getting-started/02-nextjs-app-router.mdx @@ -329,12 +329,10 @@ export default function Chat() {
{ e.preventDefault(); - const newMessages: CoreMessage[] = [ + setMessages(messages => [ ...messages, { content: input, role: 'user' }, - ]; - - setMessages(newMessages); + ]); setInput(''); const result = await continueConversation(newMessages); @@ -429,12 +427,10 @@ export default function Chat() { { e.preventDefault(); - const newMessages: CoreMessage[] = [ + setMessages(messages => [ ...messages, { content: input, role: 'user' }, - ]; - - setMessages(newMessages); + ]); setInput(''); const result = await continueConversation(newMessages);