Array of components gets re-render every time that a new component is added
Hi, I'm struggling to allow users to add new inputs "on-the-fly" without forcing all elements to re-render (and therefore, losing their internal state). Not sure what I'm doing wrong, see the relevant part of my code below:
any idea on how I could keep the state for the elements that didn't change? For now I'm just adding new elements into the array, but the idea is that I also allow removing them
7 Replies
I'm not sure this is the problem, but the item in
Index
is a signal, so I think that the <>{reference}<>
in your Index
child should be <>{reference()}<>
.mm I don't think this is the issue,
references
is the signal, not reference
, right?
The main issues is that when a new element is added all of the components in the array get re-(generated/rendered), but I am not sure how to get past that and only re-render elements when they actually change, not when a new element is addedreference
is a signal and index
is fixed. With For
, it's the other way around.SolidJS
Solid is a purely reactive library. It was designed from the ground up with a reactive core. It's influenced by reactive principles developed by previous libraries.
you're totally right, completely missunderstood how it worked, will give it a go, thanks!
You also might try using
For
instead of Index
. Though thh I don't really grok the difference between the two.yep, my loop was before with a
For
, but I've changed to Index
hoping that would help 😦
ahhh, I see, completely missed that, thank you!!!