What is the proper way to insert into an array that is rendered with <For>?
The docs talk about inserting at an arbitrary index:
https://docs.solidjs.com/concepts/stores#appending-new-values
When I used an index other than
array.length
, it replaced the item at that index rather than inserting a new one, unless there is some profound problem with my rendering.Stores - Solid Docs
Documentation for SolidJS, the signals-powered UI framework
3 Replies
The setStore path syntax is more like a replacement/update than an insert
Since JS array starts at 0, "array.length" is out of bound for the current array -> "replacing" there can be seen as appending after the end
Personally, I'd retrieve the whole array at once, do "toSpliced" to insert into middle, then setStore again
I would use
produce
and splice it inThat’s what I ended up doing