Next.js Discord

Discord Forum

Can I turn these 2 Components into Server Components ?

Answered
Sun bear posted this in #help-forum
Open in Discord
Sun bearOP
I've recently read that it's recommended to try and turn as many components as possible into server components for faster client loading, and I wonder if it would be possible to turn my sidebar into one, while keeping the same functionality as it currently has, here is the code:
removed
Answered by Plott Hound
Yeah your code is absolutely fine! Don’t worry about trying to make everything a server component.
View full answer

13 Replies

Plott Hound
in the first code, you'd need to replace useState with another solution to handle the hover. and in the second code using usePathname and useTheme() will make you need to flag it as use client too
bext bet is to isolate anything using these functions/hooks into client components and keep everything else as server components
@Plott Hound bext bet is to isolate anything using these functions/hooks into client components and keep everything else as server components
Sun bearOP
I feel like that would complicate the workflow a bit too much for a beginner like myself though. I think it would be better to leave these two alone then, at least for now.

Since these components are also pretty small I don't even think they use that many resources anyway, I mean it's just a sidebar with some buttons. Maybe if it would add alot of time to the loadtime like 0.5 seconds more or so then it would be worth splitting things up but since most of the sidebar's content is components which require the client stuff I don't see what difference it would make, unless loading a rectangle saves lots of time up.

I'm just speaking out of my head here, it may be worth it but I don't have enough experience to tell.
Answer
Plott Hound
I doubt this will even impact your site speed at all
@Plott Hound Yeah your code is absolutely fine! Don’t worry about trying to make everything a server component.
Sun bearOP
Thank you very much. I've wrote it with the help of Chat GPT and a lot of headache 😄
@Sun bear Thank you very much. I've wrote it with the help of Chat GPT and a lot of headache 😄
Plott Hound
My pleasure. Good luck with the rest of your app
@Plott Hound My pleasure. Good luck with the rest of your app
Sun bearOP
Thank you very much! 🙏🏻
@Sun bear Thank you very much! 🙏🏻
Plott Hound
Mark this as solved if you wouldn’t mind
@Plott Hound Mark this as solved if you wouldn’t mind
Sun bearOP
I have no idea how to do that.
Please let me know if you know
Plott Hound
Someone else did it. Thanks
Sun bearOP
Glad to hear that. I will close this now.