S
SolidJS2y ago
zimo

call `createServerData$` outside Route?

Can I call createServerData$ outside of a Route? I want to put it in a header that is outside of my routes. Do I need to create a "master route" that has children?
2 Replies
thetarnav
thetarnav2y ago
I think that createServerData$ is routeData + useRouteData + createResource + server$ Why not use just use createResource + server$? if you want to call it in root, you don't get any code-splitting benefit of routeData ah nvm, it's a wrapper around createRouteData, not routeData but does it really have a limitation that is has to be called in a route?
zimo
zimoOP2y ago
hey thanks @thetarnav I'm pretty new to Solid Start so I actually didn't even know about the standalone server$... I'm using the auth.js example
const Header = () => {
const session = createServerData$(async (_, event) => {
return await getSession(event.request, authOptions);
});

return <Show when={session()} ...
};
const Header = () => {
const session = createServerData$(async (_, event) => {
return await getSession(event.request, authOptions);
});

return <Show when={session()} ...
};
I'm trying to rewrite it with only createResource + server$:
const [session] = createResource(server$(async (_, event) => {
return await getSession(event.request, authOptions);
}))
const [session] = createResource(server$(async (_, event) => {
return await getSession(event.request, authOptions);
}))
Normally it seems like createResource should take an async function so I'm not 100% sure if I did this right. Huh, actually the original
const session = createServerData$(async (_, event) => {
return await getSession(event.request, authOptions);
});
const session = createServerData$(async (_, event) => {
return await getSession(event.request, authOptions);
});
worked. I just accidentally had my header inside the routes instead of outside:
<ErrorBoundary>
<Routes>
<Header />
<FileRoutes />
</Routes>
</ErrorBoundary>
<ErrorBoundary>
<Routes>
<Header />
<FileRoutes />
</Routes>
</ErrorBoundary>
<ErrorBoundary>
<Header />
<Routes>
<FileRoutes />
</Routes>
</ErrorBoundary>
<ErrorBoundary>
<Header />
<Routes>
<FileRoutes />
</Routes>
</ErrorBoundary>
I'm still a bit curious how the createResource + server$ would work
Want results from more Discord servers?
Add your server