Would this break reactivity?
I'm new to signals. The solidstart tutorial mentioned that destructuring may break reactivity in components. I don't fully understand that just yet and wonder if that means the following hook would break reactivity. This is a convenience hook I'm writing to simplify usage of the
better-auth
useSession hook.
If it can potentially break reactivty, how would you suggest accomplishing the goal of unpacking the data
field into user
and session
?
3 Replies
This is fine, so long as unpacked is called in a tracking context
The destructuring problem is an issue (=doesn't track) when it's done outside a tracking context, because the track occurs on property access (unless it's on function call, as when calling signals), and that's occurring outside the tracking context
Ripping apart an object and reassembling another just to access a single property isn't great form.
If you require the “object ergonomics” then put in the work to create a reactive object with getters.
As such it's the idiom that
props
use and is practised frequently.
Personally I start with utility functions and often don't get to the point where I have need for the object as a bag of methods semantics
All these really are, are derived signals.
Alternately if your pattern of usage is to capture the session result
inside memo/effect functions to be (synchronously) shared throughout their logic then use:
thank you