async function getData(): Promise<Container[] | null> {
const response = await fetch(`http://localhost:5236/api/v1/Flowers?all=true`, {
cache: "force-cache",
});
if (!response.ok) {
throw new Error(`Request failed with status code ${response.status}`);
}
return response.json();
}
export default async function ContainerDataTableComponent() {
const data = await getData();
return <div>
{
data
? <DataTable columns={columns} data={data}/>
: <div>Loading...</div>
}
</div>
}```
In my back, I got 5* requests to my controller `GetFlowers`
Thanks! ❤️
#Is this code well-written ? (Small, beginner)
67 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)
Can it be improved ?
via Postman, it sent only one request, and it working like a charm.
via next, it's sending a lot of requests and I don't know, may be caused due to shadcn datatable
via browser?
OH
OH
this is a client component
bruh
Its good if its a server component
but for client component, put it inside a useEffect
there does not need to
if you import this component to a "use client" file, then it will be acted as a client component
Someone told me that everything should be server, instead of hooks, etc.
he meant that you should less side effects as much as possible and prerender stuff
that doesn't mean client-side stuff is bad
if getData() is initiall fetched, then you are right: it should be done in the server
They told me that client-side is prefered for client-interaction
Well then for my thing, only fetching and create a DataTable, why it should be client ?
i didnt say that it should be client
but since you imported the component to a shadcn component or a "use client" component it BECOMES a client component
What
I mean, I'm using a shadcn component inside a server component
DataTable is a client component
yes, and where is ContainerDataTableComponent() is being used?
Inside a server component
can I see that "server component"
import ContainerDataTableComponent from "@/app/containers/page";
export default function DockerContainers() {
return <section className="flex flex-col gap-10">
<h1 className="text-3xl font-semibold">Your containers</h1>
<ContainerDataTableComponent/>
</section>;
}
where is DockerContainers() being used
Inside a server component (page.tsx)
import {Inter} from 'next/font/google'
import DockerContainers from "@/components/DockerContainersComponent";
const inter = Inter({subsets: ['latin']});
export default function Home() {
return <main>
<h1 className="text-red-500">DockSweeper</h1>
<DockerContainers/>
</main>
}
That's weird right
But I think that it could come from the datatable component from Shadcn/ui
Like every interaction or I don't know, fetch
that shouldn't happen as ContainerDataTableComponent is not a client component
Yeah and it does the same
so its not DataTable...
It's spamming request and I got that :
Unhandled Runtime Error
Error: async/await is not yet supported in Client Components, only Server Components. This error is often caused by accidentally adding `'use client'` to a module that was originally written for the server.
That's my file project structure if it can help
can you tell me
where is ContainerDataTableComponent located using the Search function
i dont have enough information
can you send full error?
what file caused that error
I now having that :
For this page :
import {columns, Container} from "./columns"
import {DataTable} from "@/app/containers/data-table";
async function getContainers(): Promise<Container[] | null> {
const response = await fetch(`http://localhost:5236/api/v1/DockerContainer?all=true`, {
cache: "force-cache",
});
if (!response.ok) {
throw new Error(`Request failed with status code ${response.status}`);
}
return await response.json();
}
export default async function ContainerDataTableComponent() {
const data = await getContainers();
return <div>
{
data
? <DataTable columns={columns} data={data}/>
: <div>Loading...</div>
}
</div>
}
so do you know what file causes this error
try to troubleshoot first then
Call Stack
resolveModelToJSON
node_modules\.pnpm\[email protected][email protected][email protected]\node_modules\next\dist\compiled\react-server-dom-webpack\cjs\react-server-dom-webpack-server.edge.development.js (2102:12)
resolveModelToJSON
node_modules\.pnpm\[email protected][email protected][email protected]\node_modules\next\dist\compiled\react-server-dom-webpack\cjs\react-server-dom-webpack-server.edge.development.js (1399:13)
stringify
<anonymous>
stringify
node_modules\.pnpm\[email protected][email protected][email protected]\node_modules\next\dist\compiled\react-server-dom-webpack\cjs\react-server-dom-webpack-server.edge.development.js (2546:13)
processModelChunk
node_modules\.pnpm\[email protected][email protected][email protected]\node_modules\next\dist\compiled\react-server-dom-webpack\cjs\react-server-dom-webpack-server.edge.development.js (2252:25)
retryTask
node_modules\.pnpm\[email protected][email protected][email protected]\node_modules\next\dist\compiled\react-server-dom-webpack\cjs\react-server-dom-webpack-server.edge.development.js (2299:6)
performWork
node_modules\.pnpm\[email protected][email protected][email protected]\node_modules\next\dist\compiled\react-server-dom-webpack\cjs\react-server-dom-webpack-server.edge.development.js (1694:13)
listOnTimeout
node:internal/timers (569:17)
process.processTimers
node:internal/timers (512:7)