Skip to content

Minor bug in Next.js app router docs example code #3126

Closed
@TrevinAvery

Description

@TrevinAvery

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingdocsImprovements or additions to documentation

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions