Questions tagged [getstaticprops]

90 questions
14
votes
3 answers

NextJS, _app, SSG, getInitialProps vs getStaticProps and how am I supposed to stick to DRY?

I know that the topic isn't new and I found (and read) a few discussions. What I couldn't find is an answer to my still remaining question. How do others work around the problem of not being able to use getStaticProps in _app.js ? getInitialProps is…
SMEETT
  • 166
  • 1
  • 9
14
votes
2 answers

How to generate a menu based on the files in the pages directory in Next.js

I am trying to create a menu component that reads the contents of the pages folder at build time. However I haven't had any success. Here is what I have tried: import path from "path"; import * as ChangeCase from "change-case"; export default class…
kaan_a
  • 3,503
  • 1
  • 28
  • 52
8
votes
1 answer

Revalidate doesn't work on Vercel using NextJS

I used the provided example from Vercel documentation, to fetch the data from MongoDB after every 15 seconds, but unfortunately the function doesn't work. What should I do to make it work as expected? export async function getStaticProps() { const…
user3630024
  • 111
  • 1
  • 8
7
votes
2 answers

Can I use the UseEffect hook inside getStaticProps?

I have a doubt.. can I use a useEffect inside getStaticProps? I'm trying to run a function inside getStaticProps... it works.. but I don't know if it is the recommended thing to do. useEffect(() => { remarkBody() }, [body,…
user13680445
3
votes
0 answers

how to create sitemap with NextJs getStaticProps

I'm trying to use NextJS to generate the sitemap of my website. But it does have a lot of links. I would like to avoid processing all the links every sitemap.xml is accessed. I have something like this: import { GetServerSideProps } from…
Felipe César
  • 1,234
  • 2
  • 16
  • 34
3
votes
1 answer

Next.js withPageAuthRequired with getStaticProps

According documentation @auth0/nextjs-auth0 we can use withPageAuthRequired for trigger login screen on pages required login. short variant: export const getServerSideProps = withPageAuthRequired(); But what to do if I need to use getStaticProps for…
Arhitector
  • 41
  • 2
  • 5
3
votes
1 answer

NextJS getStaticProps not passing returned props to page

I am having some issues getting my getStaticProps function to pass the returned props into template pages in NextJS. Here is the code I currently have for the dynamic page template. // src/pages/blog/[slug].js import React from 'react'; import…
2
votes
0 answers

Next Js - getStaticProps is not returning anything

I don't know why my getStaticProps() does not return anything. I hopped through many articles but can't find a solution. The console.log gives me undefined on page.js and categories.jsx both. I am using app router. app/page.js import Landing from…
Sebak Thapa
  • 171
  • 2
  • 7
2
votes
0 answers

RTK Query in SSG - Extracting Rehydration Info not working as expected

According to the steps mentioned in the RTK Query documentation for SSR: I first configured next-redux-wrapper. Then, I called two lines of code in the SSG call. The third step was to add extractRehydrationInfo, which I also added. The…
2
votes
2 answers

fetch data by useEffect in a server side rendering page

I have a project with react js and next js. I am developing a dynamic page, with getStaticPaths and getStaticProps. So I am fetching most of the data in getStaticProps to make the page be rendered on server side. But there are some data which I…
2
votes
0 answers

Getting "TypeError: Cannot read property 'replace' of undefined using Nextjs

I'm learning Nextjs. Getting this error while trying to fetch data from a firestore in dynamic pages ~ "[].js". replace is a method used to transform the address prop in the EventLogistics component used below. import { getAllEvents,…
2
votes
0 answers

Should NextJS getStaticProps be used to serve a user-make-content web app?

The original question was posted at Github discussion. But no one has answered the question yet. So let's try my luck here. Context I am trying to build a platform (a.k.a. web-2.0) website, where users will create the majority of the content, say…
Ivan Wang
  • 8,306
  • 14
  • 44
  • 56
1
vote
1 answer

White label Next 13 app, get static data at build time?

I’m working in Next 13 and would like to use the new app router for this project. We are going to have different static data for different customer builds of the app. They aren’t page routes like generateStaticParams would generate, it’s more like a…
Brian B
  • 11
  • 3
1
vote
1 answer

Next js getStaticProps isn't working and returning Undefined

I'm trying to fetch some data from an Api using the getStaticProps but when I pass it to my component It returns undefined. Here is the code of the function : export async function getStaticProps() { const res = (await…
1
vote
1 answer

Next.js getStaticProps doesn't run and on next build shows error

import { medusa } from "@/app/requests/medusaClient"; import { useState, useEffect, JSXElementConstructor, PromiseLikeOfReactNode, ReactElement, ReactNode, ReactPortal } from "react"; import { Product} from "@/app/models/productModel"; import {…
1
2 3 4 5 6