Property inside <For>
does not update
#1975
Unanswered
ramadhanafif
asked this question in
Q&A
Replies: 1 comment 3 replies
-
Update: so I tried to do a deep copy for the signal, and it works. function changePos() {
setPositions((current) => {
current.forEach((element, index) => {
console.log("randomize position");
element.x = Math.random();
element.y = Math.random();
element.z = Math.random();
});
return JSON.parse(JSON.stringify(current)); // Deep-copy trick
});
} Feels like stupid and unoptimized way to solve this issue. Does anyone has a better way? |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I'm still new to webdev and to solid.
I currently trying to use
<For>
control flow to render a json data signal.This question seems similar to #813 but I don't have enough understanding about it, apologies if this is a duplicate.
This is the signal, notice I use
equals:false
because I want to enforce rerender.and this is the part where it gets called
The part where the signal gets updated has been confirmed to work correctly using
createEffect()
+console.log()
The Issue
As you can see, on the
createSignal()
part above, the object inside signal has an x, y, and z values. The issue is whenever I change the x y or z value, the signal does not gets updated.Take a look at the function below, where it will randomize x y z value, and then call the signal setter.
I expect the
randomPos()
function will rerender the section inside<For>
, but in reality it does not!However, if I add items to the signal list, it will update.
Can someone kindly give me a simple technical explanation why does it behave this way, and what are the possible solution to this issue?
Beta Was this translation helpful? Give feedback.
All reactions