ttt
ttt

Reputation: 6829

Is it possible to fetch data from the database server-side while using useFormStatus client-side in Next.js using the App Router?

I'm trying to create an edit-form for editing user data (name, email and password).

And I want to pre-fill the input fields with the current user data (name and email).

But because useFormStatus's pending property is a client-component feature, I can't use Next.js Server Actions to fetch data from the database (or at least I couldn't figure out how to do that). Instead I fetch the data from a client component using SWR or the fetch() function.

My question is: "Is my only option fetching the user data from the database from the client's side or is there a way to fetch the data on the server side and filling the html input fields on the server-side?"

Upvotes: 1

Views: 118

Answers (1)

ttt
ttt

Reputation: 6829

Figured it out.

I've split the single client component into two components, the server component passes down the current user data via parameters to the client component.

Upvotes: 1

Related Questions