
Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag storeI can see you're mixing React Router with Next.js data fetching patterns, which won't work as expected. Let me explain the issue and how to fix it.
The problem is that getServerSideProps is a Next.js-specific function that only works in the Next.js Pages Router. However, your code is using React Router (import { Link } from "react-router-dom"), which is a completely different routing system used in standard React applications (like Create React App or Vite).
These two approaches are incompatible - you can't use getServerSideProps in a React Router application.
If you want to continue using React Router, fetch your Sanity data using standard React patterns:
import React, { useEffect, useState } from 'react';
import { Link } from "react-router-dom";
import Header from "../components/Header";
import "./Home.css";
import { Carousel, Card } from 'antd';
import { client } from "../lib/client";
const Home = () => {
const [products, setProducts] = useState([]);
const [bannerData, setBannerData] = useState([]);
const [loading, setLoading] = useState(true);
useEffect(() => {
const fetchData = async () => {
try {
const productsQuery = `*[_type == "product"]`;
const productsResult = await client.fetch(productsQuery);
const bannerQuery = `*[_type == "banner"]`;
const bannerResult = await client.fetch(bannerQuery);
setProducts(productsResult);
setBannerData(bannerResult);
} catch (error) {
console.error('Error fetching data:', error);
} finally {
setLoading(false);
}
};
fetchData();
}, []);
if (loading) return <div>Loading...</div>;
return (
<div className="container">
<Header/>
<Carousel autoplay className="carousel">
{bannerData?.map((e, index) => (
<img key={index} src={e} className="carousel-img" alt="carousel" />
))}
</Carousel>
<div className="cards">
<Card className="card">
{products?.map((product) => (
<div key={product.Slug}>
<h1>{product.Name}</h1>
<img src={product.Image} alt={product.Name} className="card-content"/>
<br />
<Link to="/categories" state={product.Genre} className="link">
Shop Now
</Link>
</div>
))}
</Card>
</div>
</div>
);
}
export default Home;If you actually want to use Next.js for server-side rendering and SEO benefits, you'll need to migrate from React Router to Next.js. Your getServerSideProps code would then work, but you'd need to:
react-router-dom with Next.js's built-in routing<Link> component from next/linkpages directoryCheck out the Next.js Pages Router documentation for more details on how this works with Sanity.
key prop on your carousel items should be more specific than just the array indexThe choice between React Router and Next.js depends on your project requirements - Next.js offers better SEO and server-side rendering, while React Router gives you more flexibility for client-side applications.
Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.
Content operations
Content backend


The only platform powering content operations
By Industry


Tecovas strengthens their customer connections
Build and Share

Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag store