Questions tagged [getstaticprops]

90 questions
1
vote
0 answers

getStaticProps is always undefined in component

I've followed examples online exactly to use getStaticProps but my component always gets the return from it as undefined. In the code I provided, 'posts' is always undefined and I get a type error of 'Cannot read properties of undefined (reading…
1
vote
1 answer

Next.js test of using static and serverside props requires that I check for component props Object not null

I created a project to get familiar with Next.js getStaticProps and getServerSide props. I have a simple component that renders a table row based on user data. I haven't been able to detect a time when the object was null, but if I don't check for…
user1079785
  • 137
  • 2
  • 7
1
vote
1 answer

TypeError: Failed to parse URL in getStaticProps and data fetch

I have a problem with getStaticProps in NextJS, i try to load specialists from API Route, but I get an error. export const getStaticProps = async () => { const specialists = await loadSpecialists(); return { props: { specialists }, …
1
vote
0 answers

Module not Found after commenting function in Next.js

Could someone explain what is going. I have been trying to follow this tutorial https://nextjs.org/learn/basics/data-fetching/implement-getstaticprops I'm currently having issues with getStaticProps to work aso I started poking around and when…
1
vote
0 answers

prefetch data with header and body next.js

I have question about prefetching data. As i know, normally we can not prefetch data with header and body in getstaticprops nextjs 12 or new fetch way in nextjs 13 because it rendered on the server and we send header and body from client. I searched…
alireza
  • 83
  • 2
  • 9
1
vote
0 answers

Pass props to Layout in NextJs

import Head from "next/head"; import Image from "next/image"; import { Inter } from "@next/font/google"; import styles from "../styles/Home.module.css"; import Layout from "../layouts/Layout"; const inter = Inter({ subsets: ["latin"] }); export…
karthi
  • 31
  • 2
1
vote
0 answers

Where should I export server code in nextJS in case of code splitting?

In a nextJs project connected to mongoDB, I have multiple database connection in multiple getStaticProps and getStaticPaths functions. The code works but is repeating multiple times in my project : const client = await…
Keitaro
  • 93
  • 2
  • 11
1
vote
1 answer

NextJS getStaticProps with Typescript

I'm following a NextJS course, however I want to use Typescript - I've read a github discussion forum, but cannot seem to understand why there is an error on the 1st function below, but not the second? export async function getStaticProps():…
RamanSB
  • 1,162
  • 9
  • 26
1
vote
1 answer

getStaticProps runs on every request

when I saw the doccumentation of Nextjs I found out that the difference between getServerSideProps and getStaticProps is that the first runs on every request while the second runs in the background and when using revalidate. but here I have this…
Salvador
  • 13
  • 3
1
vote
1 answer

Firebase/NextJS: Can't access subcollections for dynamic routing

I'm building a story editor where you can write stories and separate them into different chapters and I'm having trouble accessing my subcollection for NextJS's "getStaticPaths" because every document is a UUID. I have data stored in a Firebase…
1
vote
0 answers

Next.js getStaticProps/getServerSideProps best use case

I have a blog that is using getStaticProps + getStaticPaths to generate pages from headless WP - all good. Then I have a component that is connecting to the database to allow me to link to the next post in any within any individual category. This…
1
vote
1 answer

Problem fetching data in react using getStaticProps

I'm currently trying to fetch some data in my Next.js project using the getStaticProps() function and I continue to get this error: TypeError: Cannot read property 'map' of undefined My code looks like this: export const getStaticProps = async ()…
1
vote
0 answers

Nextjs, catchall, static generation and redirects

I have a website using nextjs 10.1 I am using SSG and a catchall strategy, i.e. under /pages, I have -pages --[...slug] ---index.tsx and in my index.tsx I have export const getStaticProps: GetStaticProps = async (context: any) => { const { params,…
1
vote
0 answers

undefined getStaticProps causes build failure on page that doesn't exist

I'm fetching page data from a cms, so far I have only one page in pages/posts. pages/posts/[slug].js import { getAllPostsWithSlug, getPostAndMorePosts } from '../../lib/api'; export default function Post({ post }) { const router = useRouter(); …
agricola
  • 11
  • 1
  • 2
1
vote
1 answer

Do I need to use revalidate key in getStaticProps Next.JS for lists in page?

I'm making static e-commerce app with Next.JS. I have products directory with index.js and [id].js files. Do I need to use revalidate: someTime in products/index.js file which returns list of all products for keeping list up to date? Or it's feature…
andrewnosov
  • 374
  • 4
  • 14