#Nothing is getting rendered on making api call in server.

3 messages · Page 1 of 1 (latest)

tropic meadow
#

Here in this code.

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.

sturdy shaleBOT
#

🔎 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)

tropic meadow
#

@delicate cipher