T
TanStack5mo ago
fair-rose

Client-side Loaders?

I have an external @xstate/store which I use to keep track of some user preferences. Those preferences get persisted via cookies and loaded during beforeLoad. What is the correct way to populate a client side store like xstate with those values from the server? I know I could:
const { userPreferences } = Route.useLoaderData();

useEffect(() => {
preferencesStore.send({ event: "initialize", preferences: userPreferences });
}, [userPreferences])
const { userPreferences } = Route.useLoaderData();

useEffect(() => {
preferencesStore.send({ event: "initialize", preferences: userPreferences });
}, [userPreferences])
but my gut tells me this is the wrong solution. I could put preferencesStore.send({ event: "initialize", preferences: userPreferences }); in the Route's loader but that runs on both the client AND the server, correct? The preferencesStore should really only "exist" client side. WWYD?
0 Replies
No replies yetBe the first to reply to this messageJoin

Did you find this page helpful?