Server acttions and NextResponse()
Unanswered
Ocicat posted this in #help-forum
OcicatOP
Hi all.
I'm returning
return NextResponse.json({ message: 'item created' }, { status: 201 })
from a Next,js server action called from a client component and it throws an error.
"Unhandled Runtime Error
Error: Only plain objects, and a few built-ins, can be passed to Client Components from Server Components. Classes or null prototypes are not supported."
If I just return, say, a string, everything goes as planned.
What am I doing wrong?
Thanks in advance
I'm returning
return NextResponse.json({ message: 'item created' }, { status: 201 })
from a Next,js server action called from a client component and it throws an error.
"Unhandled Runtime Error
Error: Only plain objects, and a few built-ins, can be passed to Client Components from Server Components. Classes or null prototypes are not supported."
If I just return, say, a string, everything goes as planned.
What am I doing wrong?
Thanks in advance
1 Reply
@Ocicat NextResponse is not for server actions. NextResponse is needed in api route handlers.
check this out
https://nextjs.org/docs/app/building-your-application/data-fetching/server-actions-and-mutations#server-side-validation-and-error-handling
check this out
https://nextjs.org/docs/app/building-your-application/data-fetching/server-actions-and-mutations#server-side-validation-and-error-handling