Solid doesn't re-render when update the same array in createSignal
Expected behavior:
Re-render inputs every time passwords array is updated even with the same value, to avoid duplicating value in the same input.
5 Replies
This is the default behavior. If you want to change it, pass
{ equals: false }
as the second option of createSignal. See https://docs.solidjs.com/reference/basic-reactivity/create-signalI tried {equal: false}, but result is the same. Not re-render every time.
wrap each string in an object so that For can compare unique references
right now it compares strings, because those are the items, where they are compared by value, which can have undefined behaviors like this
or use Index
if you don’t plan on reordering the passwords
so it doesn't rerender because of this:
which btw can be rewritten as
then you set this value to your signal. Renders for lists in
For
/ Index
are triggered when reference / value changes, so something like from your example with
should work, but would be very inefficient, as every element would be recreated each time 1 value changes.
My suggestion is to:
- set input value by reference to the input after you change it
- consider using stores for nested objects, it just have nicer syntax and reacts to only signle element that changed
- use rather Index
than For
when the enumerating value is primitive (not an object)
So finally something like this
Also there's other way, without ref
and updating input value yourself. It's to pass a signal that does trigger when you set it, that is:
example with signal & For
for store & Index I have no better idea yet than that:
because store also trigger change only when value is different, that's why I set passwords value to ""
then to desired value. Wrapped in batch, so that first set to ""
doesn't trigger anything - without batch input value would change to ""
then to desired value but very quickly, this way it changes directly to desired value and is notified that it changed, even though it didn't@Maciek50322 Thank you for your clarifying. It helps me a lot.