Next.js Discord

Discord Forum

conditional server or client side file

Answered
Abyssinian posted this in #help-forum
Open in Discord
AbyssinianOP
I am working on a website/app that is dynamic on the web, but static for tauri. Is there anyway I can set a file such as server.ts to be server sided or client sided based on the env variable?

some thing like:
process.env.STATIC === 'true' ? 'use client' : 'use server';

11 Replies

Netherland Dwarf
Hmmm
@Abyssinian use client is only if your page or that file requires hooks or states
Otherwise just leave it as use server
@Netherland Dwarf <@648929307741257729> use client is only if your page or that file requires hooks or states
AbyssinianOP
regardless I want the components/actions to be executed on the server or client based on the platform
because for tauri or electron, there is no server
@Abyssinian regardless I want the components/actions to be executed on the server or client based on the platform
Bengal
'use client' and 'use server' don't do what u think
use client is still rendered on the server, but client side hydrated
'use server' is to run a function on the server
a server component is run ONLY on the server (static html)
you can use dynamic import with ssr: false to do this I think to opt out of server side rendering (ssr, which is what use client does) and have the component run only on the client (csr)
Answer