Trying to understand stores in a reactive scope
I've started rewriting my code to use stores instead of lots of signals, and I'm not sure if I understand how they work when passed into a reactive context. This is my store:
I then have a
ClipTree
component to which I pass all clips:
Lastly, my store gets updated when receiving a callback (from Tauri) like so.
This does not update one of the clips in my clip tree component. I expected that if you update a specific clip with path syntax, any component that has all clips passed into it as a prop in a reactive context ({}
) would update.
Am I understanding incorrectly how this works? Do I need to write my <ClipTree>
in a different way?7 Replies
This works as expected:
https://playground.solidjs.com/anonymous/e679ac59-1b39-4d50-a80c-7af5fdcf669b
Solid Playground
Quickly discover what the solid compiler will generate from your JSX template
This does not update one of the clips in my clip tree component.That specific setter update seems to target a specific clip with a matching
id
and updates its name. So I don't know what “does not update one of the clips” means in this context; that would only make sense if there are multiple clips with the same id
in the clips
array.
any component that has all clips passed into it as a prop in a reactive context ({}) would update.You are not disclosing what you are actually doing inside of the
ClipTree
component. Given just
all we know is that explorer.clips
is passed into the component.
What your component reacts to depends entirely on what it accesses.
In the context of the example that I gave
each item's name
is accessed, so the component will react when the name
of that one item is changed.Hey @peerreynders, thank you for taking the time to answer. I'm relatively new to solid, so it's much appreciated 🙂
So I don't know what “does not update one of the clips” means in this context; that would only make sense if there are multiple clips with the same id in the clips array.Yes, I meant that I have a list of multiple clips (each with a unique ID), but I don't see any changes when mutating the store. What I'm doing internally is pretty much like what you show in the playground, and there it clearly works. This leaves me wondering where the difference lies, so I'm diving a bit deeper.
One thing to look for is that you don't break reactivity, e.g.:
Ah, no, I don't destructure, but I didn't know that, so thank you 🙂
Here's the (stripped down) version of the component
LabelIconRow
eventually puts the text into a <span></span>
Really gotta get to bed now, but I will investigate further in the morning. At least it's good knowing that it's supposed to work, so I know to search for where the reactivity breaks downSolid Playground
Quickly discover what the solid compiler will generate from your JSX template
Hmmm, if I do this it does work, so either I'm doing providing the path incorrectly, or that triggers some more fine-grained reactivity I'm not handling correctly in the component.
vs
Ah, I found the culprit. It's that
LabelIconRow
, which does something internally that breaks the reactivity. Not sure what yet, I'll figure it out, but if I change its internals to literally {props.text}
everything works as I expected
Thank you very much for your help, @peerreynders. You pointed me in the right direction and I learned something along the way (about destructuring for example) 👍