signal of createResource is not reactive inside a For component
When passing the signal obtained in a request made by createResource and looping the results of that the reactivity when the resource mutate is lost.
It works fine if i iterate the signal with a .map() so i don't know what can be the issue.
10 Replies
without an example code, it's hard to say though. maybe you're doing along the lines of
then this won't work as the resource's return is just a signal with some getters mashed in
if you're returning nested data and wants fine-grained reactivity,
createResource
with storage : createDeepSignal()
backed by createStore
might be a good option
there's also an implementation of createDeepSignal
in solid primitives alreadyI'm doing this for the signal of the resource
in a create effect i mutate it
and using a map the reactivity works and everything works fine
but if instead of a .map i use <For each{devices()}> it doesn't work
I'll look into the createDeepSignal but it's strange that it works with map and doesn't work with <For> no? How can I get the createResource return that fine-grained reactivity?
I'll look into the createDeepSignal but it's strange that it works with map and doesn't work with <For> no? How can I get the createResource return that fine-grained reactivity?
alright, forget about the fine-grained for a moment
For
compares individual items by reference and re-run the block only when they differ
but deep signal + store's path setter and utilities could helpers could help with this somewhat thoughhmm i have this function
I think i'm creating a new object as you said no?
maybe a second look will click things for you
as i say this works fine with .map but i imagine this is due to that it renders the whole loop again
yeah, i know, that's what
For
and Index
are fori don't undertand much 😅
how would the code look?
devices().data.map....
worked because you returned a new object { ... devices, ...}
data
is also a new array now
but to For
, that isn't enough
as it also compares the individual items by reference
devicesArr[index].status = message.status;
here devicesArr[index]
is still the same object as before
now it's more clear. Thanks!