#Nextui tabs
24 messages · Page 1 of 1 (latest)
🔎 This post has been indexed in our web forum and will be seen by search engines so other users can find it outside Discord
🕵️ Your user profile is private by default and won't be visible to users outside Discord, if you want to be visible in the web forum you can add the "Public Profile" role in id:customize
✅ You can mark a message as the answer for your post with Right click -> Apps -> Mark Solution
(if you don't see the option, try refreshing Discord with Ctrl + R)
mh, nope... this is a good place for the question too 
was just a suggestion 🙂
ok, but still don't needlessly push away people
@thorny tangle 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 TabsComponent
it works the same way as passing a server component as children to a server component.
<ClientComponent>
<ServerComponent />
<ClientComponent />
@covert creek 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
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
For posterity (and the forum):
// 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>;
};
@covert creek 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
Mh, not necessarily. You can conditionally render tabs based on the active tab state if nextui exposes that information.
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
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.