-
This might sound dumb but I have this simple list of divs: const list = van.state(['a','b','c']);
const dom = () => {
return div(list.val.map(x=>div(x)))
}; Then when I try push an element to the list: const change = button({
onclick:()=>{
list.val.push('x');
}
}, 'click'); It doesn't update the list in the dom. I tried experimenting a bit and then found this: const change = button({
onclick:()=>{
list.val.push('x');
list.val = [...list.val];
}
}, 'click'); It works fine now. This does the same when I set the values individually in the array. But is there another way of updating an array state without making a copy/changing the reference to another array object? Thank you for your awesome work! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
See the relevant discussion in this thread: #207 (reply in thread). For the UI to be reactive to |
Beta Was this translation helpful? Give feedback.
See the relevant discussion in this thread: #207 (reply in thread).
For the UI to be reactive to
push
ofArray
s, you can consider usingvanX.list
(part of VanX, the official VanJS extension).