Destructuring with splitProps
Hi there,
Are there any disadvantages of destructuring the
local
object compared to the second example?
vs
8 Replies
yea, you lose reactivity
you access all getters during destructuring
the reason why you need to use
splitProps
in the first place is because we want to perserve reactivity.Ah, ok. Thanks 👍
SolidJS
Solid is a purely reactive library. It was designed from the ground up with a reactive core. It's influenced by reactive principles developed by previous libraries.
here is a good tutorial that talks about exactly this
So there is no way to destruct props then? A bit cleaner Imo to write
<div>{foo}</div>
than having to repeat "local", as <div>{local.foo}</div>
everywhere.The only thing you can do is put them in a function which makes sure that reactivity is perserved:
But you can't destruct props.
This is the design Solid chose. They transform component props into getters.
That's why you can write something like
<Mycomp myProps={signal()} />
and even tho the signal accessor is called here, it'll still be reactive.
because solid essentially does this in the background:
Thanks for the detailed answer, I understand now 👍
You're welcome :zzz_flushedfroge: happy to help