Skip navigation
How to refactor an existing client component into a server component?
0:00 / 0:56

How to refactor an existing client component into a server component?

Alex Sidorenko

@asidorenko_35K followers

Visit on X
1,092 likesDownloadOriginal post

112,433 views

How to refactor an existing client component into a server component? 1. Move the state to the URL 2. Move data fetching to the server 3. Isolate interactivity into a smaller client component

10 Comments

Comments from the original post on X (Twitter)

  • Armando⚡️'s profile picture

    @manduks

    You are killing it, lot of things I learned seeing your videos, will be nice to have a web page that renders all these tips so I don’t have to bookmark them 😅, anyways awesome content!

    6 likes

  • Alex Sidorenko's profile picture

    @asidorenko_

    Thanks, I am working on the dedicated page. *Also secretly hoping that @X will implement better UI for tweet collections so I don't have to build anything

    5 likes

  • Fredkisss is on 🦋 blue sky 🦋's profile picture

    @fredkisss

    Now what is missing is adding Suspense to show loading states on the server, or use useTransition (in the Search client component) to show loading state on the client.

    5 likes

  • Nithur's profile picture

    @NithurM

    It would be cool if we can generate these pages statically

    4 likes

  • Alex Sidorenko's profile picture

    @asidorenko_

    We can. 1. Substitute query params with dynamic routes. So the route looks like this /movies/doctor instead of /movies?search=doctor 2. Pass most popular search requests to generateStaticParams

    18 likes

  • Ben Gibb's profile picture

    @bWgibb

    @asidorenko_ pardon the noob but sincere question, but what is the purpose of doing this? How is the code better in moving to the server?

    4 likes

  • Alex Sidorenko's profile picture

    @asidorenko_

    Good question, nothing noob about it. - Ship less JS to the client (improves time to interactive) - Can use secret keys when fetching data - Less client-side re-rendering - Can pre-generate popular search queries at build time - State in the URL is often better UX

    19 likes

  • Armo's profile picture

    @Armo_MXT

    Thanks for creating amazing content!

    2 likes

  • Hemanta Sundaray's profile picture

    @hemanta_io

    Make some videos on Next js middlewares.

    1 like

  • Alex Sidorenko's profile picture

    @asidorenko_

    Do you have any specific cases in mind?