Next.js Discord

Discord Forum

Question about ssr logic functionality

Answered
gin posted this in #help-forum
Open in Discord
ginOP
If i have a component without "use server" or "use client" and i export two functions one using document and one using a server only function will nextjs automatically split that up so i wont get any errors?
Answered by gin
i will split both functions into other files with the correct client/server context
View full answer

12 Replies

"use server" is not for server components
components are server components by default and "use client" is for indicating your component is client component
"use server" is for server actions
ginOP
i know that already but can u answer my question
try this instead
ginOP
example:
import {cookies} from "next/headers";
export function getServerLinkToken(name: string): string | undefined {
  const store = cookies();
  return store.get(name)?.value;
}
export function getClientLinkToken(name: string)
{
// client code
}
ginOP
alright i see just importing cookies will throw a weird error mentioning /pages directory
so, question answered
ginOP
i will split both functions into other files with the correct client/server context
Answer