How to untrack() or on() a props value?
Maybe I'm thinking about this the wrong way? But I'm wondering how to
untrack()
a props value the way you'd untrack()
a signal in a createEffect
for example. Since the reactive values in props
are wrapped in a getter, it seems impossible to get the Accessor
that can be used in untrack()
or on()
.
I suppose I could derive a new Accessor
with something like:
then untrack(thing)
? But that seems like a roundabout way of doing it, would that even make sense?
Thanks!11 Replies
That's the only way of doing it, unless you want to call Object.getOwnPropertyDescriptor(props,'think') and untrack the "get" function from there
but there may not be a get function, so it's a bit tricky
I guess an untrackProp primitive could be build that does that
Thanks @fabiospampinato ! Would you consider needing to untrack a props value a code smell, signifying I might be thinking about stuff the wrong way? Or is wanting to untrack a props value a legit thing that should/could hapen
🤔 so the way I write my components I actually just pass functions and signals as props, no "props rewritten as getters" business, and untracking those is legitimate, sometimes necessary, I don't think untracking
props.foo
in Solid is any different, it's just weird to write because the props object you get is weirdah ok! i was actually toying around with passing Accessors instead of values as props, and i think it makes more sense in my mind. I understand why it was built this way, but it does seem a little weird that by default reactive values are unwrapped then wrapped again when passed down through props, and then you can't access the wrapper in the child component, you're stuck calling the getter. I'll try passing functions instead and see if that ends up making more sense. Thanks!
For reference for anyone else looking at this, this is also a good discussion on this topic https://github.com/solidjs/solid/discussions/749
GitHub
Passing signal as prop · Discussion #749 · solidjs/solid
Assuming I have a signal in a parent comp, and I want to pass the signal value to a child comp, what is the difference, in term of performance/behavior, between passing the signal value as props vs...
untrack(() => props.value)
Yeah it's definitely simpler to just do nothing 🤣 if you want to experiment with passing raw functions around I'd recommened writing yourself some kind of function that unwraps a props, so that you can handle signals, functions, or raw values, the same way
Oh nice one-liner!
Wait actually passing raw functions around I'm not sure if it works in Solid, like can you pass a raw function to any native prop? You can handle custom ones yourself, but what about native ones? I wouldn't bet that it would just work
For sure you can't pass signals as on* handlers, for whatever strange reason
for sure, i'm only thinking about for custom components that can handle functions for that stuff
The reason to me reads as "perceived simplicity > perceived value from proper types"
Which is doubly wrong from my personal point of view, because the simplicity ends up being a complication, and the value of proper types is huge