TanStackT
TanStack13mo ago
10 replies
dangerous-fuchsia

How do I access cookies from an SSR-rendered component?

I'd really love for the first paint to arrive with the user's correct dark mode theme set.

I have a very simple serverFn to grab the cookies, but it's naturally async.
export const getCookieFromRequest = createServerFn().handler(() => {
    return getRequestHeader('cookie');
});


Should I be wrapping the whole site in a Suspense and Await, or is there a better way to synchronously grab the server-side cookie value?
Was this page helpful?