SolidJSS
SolidJS9mo ago
4 replies
ctrl-z

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?

export function useUserSession() {
    const sData = useSession()

    const unpacked = () => {
        const { data, ...statusProps } = sData()

        return {
            user: data?.user,
            session: data?.session,
            isAuthenticated: data?.session.token,
            ...statusProps
        }
    }
    return unpacked
}
Was this page helpful?