Nothing is getting rendered on making api call in server.
Unanswered
ayush posted this in #help-forum
ayushOP
Here in this code.
what I am trying to do is I am fetching data from backend api which is in next itself. the data is getting fetch successfully but not passed to the client. (we need this as sidebar and product card are both client side. so they cant be rendered in server) I am using latest next version. so how do I use the functionality of serversideprops here.
import React from "react";
import { Sidebar, ProductCard } from "components";
import { useSelector } from "react-redux";
import { StoreState } from "store";
const Listing = async () => {
const response: any = await fetch(
`${process.env.NEXT_PUBLIC_ENDPOINT}/api/products`,
{ method: "GET" }
);
const data = await response.json();
console.log(data);
console.log(process.env.NEXT_PUBLIC_ENDPOINT, "localhost>>");
return (
<div className="p-4 flex items-center justify-center overflow-scroll">
<div className="flex gap-x-[50px] ">
<Sidebar />
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-3 overflow-scroll">
{data?.products?.map((value: any) => {
return (
<ProductCard
key={`${value.id}${value.title}`}
cardDetails={value}
/>
);
})}
</div>
</div>
</div>
);
};
export default Listing;what I am trying to do is I am fetching data from backend api which is in next itself. the data is getting fetch successfully but not passed to the client. (we need this as sidebar and product card are both client side. so they cant be rendered in server) I am using latest next version. so how do I use the functionality of serversideprops here.