Next.js Discord

Discord Forum

How to handle state with App Router server components?

Unanswered
Giant wood wasp posted this in #help-forum
Open in Discord
Original message was deleted.

2 Replies

Siberian Flycatcher
It seems almost anti-react this new way of doing things, unless I am doing something very wrong. Would it be bad practice to have a state inside the client component, that stores the props it recieves?

App router removes the need for storing server state on the client. Instead, when we want to mutate data (create a new post), we can simply update it on the server with server actions and revalidate the route path

This animation may be helpful
https://twitter.com/asidorenko_/status/1681017694072500224

And this docs section:
https://nextjs.org/docs/app/building-your-application/data-fetching/server-actions
Siberian Flycatcher
Server Actions are still in alpha, and the API may change. If you don't want to rely on them, you can simply update the data from your client component (with a POST fetch request to an API route) and do router.refresh() .

This will also re-fetch the server component and show the newly created post on the page.