Next.js Discord

Discord Forum

Use client component with media query or RSC with Tailwind classes?

Answered
Broad-snouted Caiman posted this in #help-forum
Open in Discord
Broad-snouted CaimanOP
Hi there! So, I've something like the following code:
export default async function Page() {
  const data = await getData()
  return
    <section>
      <div className="hidden sm:block"><DataTable data={data} /></div>
      <div className="sm:hidden"><DataList data={data} /></div>
    </section>
}


But I'm wondering if the following isn't better:
'use client'
export default function ClientComponent({ data }) {
  const isDesktop = useMediaQuery('(min-width: 768px)')
  return isDesktop ? <DataTable data={data} /> : <DataList data={data} />
}


Is the client version better since it only passes data for one component? The RSC version passes data to 2 components, although one of them is hidden, correct?
Answered by Stony gall
What do you mean by better? Performance wise, RSC will always perform better. You always want to use RSC for non-interactive component, you can even combine both server-component and client-component.
View full answer

6 Replies

Broad-snouted CaimanOP
bump
Stony gall
What do you mean by better? Performance wise, RSC will always perform better. You always want to use RSC for non-interactive component, you can even combine both server-component and client-component.
Answer
@Stony gall What do you mean by better? Performance wise, RSC will always perform better. You always want to use RSC for non-interactive component, you can even combine both server-component and client-component.
Broad-snouted CaimanOP
Performance wise. But how is it better if you need to pass the data to 2 different components, when client component it would be only once?
Stony gall
Broad-snouted CaimanOP
Thanks for replying!
Stony gall
👍