Closed
Description
Description
There is small bug in the doc example for Next.js app router. In the Update the UI section, the code example creates a newMessages
variable with the existing messages and the new message that was just submitted, but this is done outside of the setter function. To ensure it has the most recent version of messages
, it should instead pass a callback to the setter function.
Code example
This
const newMessages: CoreMessage[] = [
...messages,
{ content: input, role: 'user' },
];
setMessages(newMessages);
Should be
setMessages(messages => [
...messages,
{ content: input, role: 'user' },
]);
Additional context
I don't know if this is the right place to submit this issue. There was no clear "docs" options when creating the issue. I also tried to send feedback instead, but the submit button didn't appear to do anything.