Nextui tabs
Unanswered
Crème D’Argent posted this in #help-forum
Crème D’ArgentOP
Hi there,
I am using nextui tabs and I must use the tabs within client component, but the issue is that I need some tab component as server component
async components to use react suspense with it, because if I used client component it i will not work with react suspense, so any suggession please?
I am using nextui tabs and I must use the tabs within client component, but the issue is that I need some tab component as server component
async components to use react suspense with it, because if I used client component it i will not work with react suspense, so any suggession please?
23 Replies
Blue Mockingbird
maybe you can go ask in the nextui discord server
@Blue Mockingbird maybe you can go ask in the nextui discord server
mh, nope... this is a good place for the question too 

Blue Mockingbird
was just a suggestion 🙂
ok, but still don't needlessly push away people
Crème D’ArgentOP
@Blue Mockingbird ok, I think the main question isn't around nextui itself as it's around using server component within client component to make react suspense work
anyways, to answer your question. you can pass server components as props to client components. that way you can wrap your tab contents in suspense and pass them to your
TabsComponentit works the same way as passing a server component as children to a server component.
<ClientComponent>
<ServerComponent />
<ClientComponent />Crème D’ArgentOP
@not-milo.tsx thanks for your answer, but I think this way will not work as I am having multiple tabs content, as react/nextjs doesn't support named slots,
<ClientComponent>
<ServerComponentTabA />
<ServerComponentTabB />
<ServerComponentTabC />
<ClientComponent />Give me a sec
Crème D’ArgentOP
take your time
Here you go: https://github.com/milovangudelj/interleaving-tests ✨
You can pass your tabs as an array and it'll just work
You can pass your tabs as an array and it'll just work
For posterity (and [the forum](https://nextjs-forum.com/)):
// page.tsx
import { Suspense } from "react";
import { TabA } from "~/components/tab-a";
import { TabB } from "~/components/tab-b";
import { Tabs } from "~/components/tabs";
export default function Home() {
return (
<main className="flex min-h-screen flex-col items-center justify-between p-24">
<Tabs
tabs={[<SuspendedTabA key={"taba"} />, <SuspendedTabB key={"tabb"} />]}
/>
</main>
);
}
const SuspendedTabA = () => {
return (
<Suspense fallback={<p>Loading tab...</p>}>
<TabA />
</Suspense>
);
};
const SuspendedTabB = () => {
return (
<Suspense fallback={<p>Loading tab...</p>}>
<TabB />
</Suspense>
);
};// tabs.tsx
"use client";
import { Tab } from "./tab";
export const Tabs = ({ tabs }: { tabs: React.ReactNode[] }) => {
return (
<div>
<h1 className="text-xl">Tabsss!</h1>
<div>
{tabs.map((tab, index) => (
<Tab key={index}>{tab}</Tab>
))}
</div>
</div>
);
};// tab.tsx
"use client";
export const Tab = ({ children }: { children: React.ReactNode }) => {
return <div>{children}</div>;
};// tab-a.tsx
"use client";
export const TabA = () => {
return <div>Tab A</div>;
};Crème D’ArgentOP
@not-milo.tsx but this not gonna be ideal solution where the all tabs request gonna be called without event trigger specific tab
for example
TabA has request to endpoint api
TabB has request to endpoint api
TabC has request to endpoint api
all of above requests are goona be called at the same time
TabA has request to endpoint api
TabB has request to endpoint api
TabC has request to endpoint api
all of above requests are goona be called at the same time
Mh, not necessarily. You can conditionally render tabs based on the active tab state if nextui exposes that information.
Crème D’ArgentOP
the request gonna be called outside of the tabs, while we're passing the server components they will be rendered
got my point?
No, not really. Be more specific on where you think the problem is with the code above and why you think it will cause issues
Crème D’ArgentOP
the tabs api gonna be called at this point
If you fetch your data on server side everything is going to be fetched at the same time. But if you do it on client side with something like react-query, then the fetch call will happen when your tab is rendered.
Crème D’ArgentOP
it's ok mb, what I need to achieve is something different than what you provided, Thanks a lot for your time