S
SolidJS16mo ago
lemonad

createStore array containing arrays

I have a store that is an array of objects where some properties are arrays. Then I do <For each={props.store}> {(item) => ( ... <For each={item.nested}> {(item2) => ( ... In an onClick handler, I modify a property of one of the elements in the nested array but it seems the second For loop is not seeing the update. I'm not particularly surprised by this but how would I setup something like this in order for it to work?
4 Replies
mdynnl
mdynnl16mo ago
how are you setting the nested value? setStore should work. i guess you are not using setStore? maybe you could make a minimal repro in the playground. the usual pattern is to pass both getter and scoped setter via context, not that context is necessary
lemonad
lemonad15mo ago
Thanks @mdynnl, just confirming it should work made me solve it. I was setting the values properly but I had a For that was misrepresented above, it was actually more like <For each={item.nested}> {(item2) => { ... const currentClass = props.classes.find((x) => x.name === item2.data.classification.class); ... return <li>...</li>; where item2.data.classification.class was what I updated. Not sure if it was the find that broke reactivity or something else there.
mdynnl
mdynnl15mo ago
as the callback to For is like a mini component (untracked), same rules apply as components, eagerly accessing item2.data.... effectively make it static until the next time the block runs on item change
Unknown User
Unknown User14mo ago
Message Not Public
Sign In & Join Server To View
Want results from more Discord servers?
Add your server
More Posts