Prevent re-rendering many components when object in store-array is updated
I have a grid view where multiple card components are rendered.
The issue is that all cards are re-rendered when one of the cards' data is updated in the store. Is there a way to prevent re-rendering everything when one object in the array is modified?
This is how the card is modified:
and here is how i load & filter cards
8 Replies
You're not changing just one object, you're replacing the whole array
it would be better to do
This should work but you'll have to check
Alternatively use
produce
I'm not sure how to apply this to the following structure:
store -> FlashcardCollection[] -> Flashcard[]
:
Does what I sent not work?
no sir;
Property 'find' does not exist on type 'FlashcardCollection'.
The following error is a conflict between FlashcardUpdate
and FlashcardCollection
the way i setup the store is a bit awkward:
store.tsx
flashcardStore.ts
path to a single flashcard is: store.flashcards.collections[ i ].flashcards[ j ]
You could use produce and instead of doing the
map
calls like in your original post, just do the Object assign
After finding the card with find
or a normal loopI don't understand what you mean
could you please write a short example
@REEEEE Think it's a good idea to apply states to the cards as in the following example?
https://www.solidjs.com/tutorial/stores_nested_reactivity?solved
perhaps 🤔 then, It would be simpler to manage the state of each?
Tried doing it this way, assigning state getter/setter to the card objects within store. It elimiates the need to iterate over collections and cards, and doesn't cause re-rendering for other card objects 🤔
Sorry for the late response, this is what I meant
Not sure if this will work exactly but it's the general idea
I've tried this now, but it fails to render based on the changes.
I've come to a point where I need to update multiple properties at once and using signals for each property seems like a bad-practice 🤔