#A component not marked as "use client" is not being processed server-side.

16 messages ยท Page 1 of 1 (latest)

wheat bolt
#

Can NextJS convert a component to a client-side at build time w/o notifying?

mellow dirge
#

client components also run in the server so I am not sure this is your issue

#

if a component is rendered by a client component then its also gonna be a client component, but this doesn't stop it from being pre-rendered

wheat bolt
#

I have a hook that relies on being run on the server; I was under the impression that if it was going to be rendered server side then it would need to be marked with "use client". Access to env vars post build is a part of the pattern I'm needing to leverage.

Perhaps if I make the hook a context at the top level in the layout then it will be a decent work-around

#

wait, so if we develop a hook it will behave differently depending on if it's used by a server component or a client component?

#

I ask because our server-side code relies on env vars to connect to the appropriate resources depending on where it's deployed. is there a way to ensure that these hooks are only executed on the server? it was pretty cut and dry in NextJS 12 ๐Ÿ˜•

glad linden
#

You can't use hooks on the server

#

(in server components, I mean)

#

I'm not sure what you're trying to accomplish, but it sounds like you're misunderstanding something that leads you into the wrong direction

wheat bolt
#

the tutorial I took was making calls to the api using localhost:3000/api/etc so now that I've mounted my project to an actual server things aren't working. I tried to modify the hooks to use env vars but now it's just trying to resolve an env var on the client that isn't there. this all makes sense. I'm just stuck trying to figure out how to get around it.

#

figure out how the server can let the client-side hooks know where teh API service really lives ๐Ÿคทโ€โ™‚๏ธ

#

I mean, a 3rd party API call makes sense to hard code but I'm trying to figure out how to get around my own mess at this point. ๐Ÿ˜ฆ

mellow dirge
#

I am not sure I understand what you mean by hook because most of data-fetching hooks (like useSWR) relies on useEffect which doesn't work in server components

#

if you want to fetch an API in a RSC you can just do const res = await fetch(...), you don't need anything else

wheat bolt
#

the workaround I found was to assign the vars to NEXT_PUBLIC_* in the .env file to be processed when the docker build process begins.

#

thanks for helping