I have a page which is a server component. In this component I fetch data (a list of objects) using server actions. Then I pass the data to a client component that is inside the page. And in this client component I have a state that stores currently selected object from the list. The problem is that whenever I select an object from the list, all this data (list of objects) starts loading anew. How to stop it?
#Data is fetching on every state change
31 messages · Page 1 of 1 (latest)
🔎 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)
you mean, data fetching happens everytime you change the state?
@twin zodiac
it can't be
show your cardList component
how come this component is a server component?
as I understand, in this case this component turns into a client component
no?
if its put inside of another client component
did you try to console.log inside getCards()?
no, just log cards and onCardSelect in this component
can you log something below this line and check how many time it's running
maybe your CardList component is rerendering when selectedCard state changes
and your client component shouldn't be async
always it's better to make UI pieces as components - don't try to have a single component for server/client
I feel what you are gonna do - but I don't prefer this way
not a good practice
Yea, it was not the plan. I think I did it by accident actually
anyway glad to hear that you resolved the issue!
thank you both!