#Initial state as props passed by server component

32 messages ยท Page 1 of 1 (latest)

acoustic onyx
#

I have a server component that gets data from a database and passes it to the client component. My client component uses this prop as its initial state. Therefore, I could interact with the data by updating the state.

But the problem occurs when I update the state, move to another page, and return to the updated page. The state is not updated.

untold willowBOT
#

๐Ÿ”Ž This post has been indexed in our web forum and will be seen by search engines so other users can find it outside Discord

      ๐Ÿ•ต๏ธ Your user profile is private by default and won't be visible to users outside Discord, if you want to be visible in the web forum you can add the "Public Profile" role in <id:customize>

      โœ… You can mark a message as the answer for your post with `Right click -> Apps -> Mark Solution`
      (if you don't see the option, try refreshing Discord with Ctrl + R)
urban wind
#

@acoustic onyx Do you want for it to be kept on the client side? If so something like a context in a layout, local storage, or some kind of global state management library like redux or jotai would be useful.

#

If you want state derived from props on the client to magically persist back to your database... that isn't a thing.

acoustic onyx
#

Is there anyway to make the server component fetch data (newest data)?

#

I found that the server component only call api once time although i go arround the site

urban wind
#

that is expected, the data is cached client side

acoustic onyx
#

can I remove this

#

I have added export const revalidate = 0; . But it not works

urban wind
#

I am not sure if it caches the RSC, or the fetch request

acoustic onyx
#

I dont use fetch, so it might be RSC

rose berry
#

You'll need something to handle the client side fetching for when you return to the page

#

I use react query in the RSC which passes dehydrated data to the client and the client hydrates that data and keeps things updated

urban wind
urban wind
#

something I would check is if the route is marked as static or dynamic when you build the page

acoustic onyx
acoustic onyx
rose berry
rose berry
#

I burned a lot of time trying to fight with what you're experiencing and found the react query solution I linked to be the best

brazen needle
#

My client component uses this prop as its initial state. Therefore, I could interact with the data by updating the state.

What type of interaction are you talking about? Can you describe the use case?

dawn current
#

Why do always people get help but I dont ๐Ÿ˜„

lament path
dawn current
lament path
#

May be they have 100 friends.

dawn current
#

Yeah I'm sure they do ๐Ÿ˜„

#

Maybe we can help each other then, what's the issue for you?

lament path
#

Nothing for now. I was just checking here randomly.

dawn current
#

Ahh I see, you can check on my post it still has no response to it whatsoever ๐Ÿ˜„