getStaticProps() is not running
Answered
Black Vulture posted this in #help-forum
Black VultureOP
I'm trying to grab props from a folder that I have the path to in my root directory. I'm certain that the json parsing is working fine and the helper functions are working fine (I can log them), but getStaticProps() is not able to pass it as a prop. This is my function:
And it's within a posts.ts file within a lib/ folder in my root directory. I have also tried running this from the page it is meant to support. Attached is a screenshot of the error I am receiving, and
Any help appreciated. Thanks in advance!
export default function getStaticProps(){
let allPostData = getSortedPostsData();
console.log("Im useful!")
return { props: { allPostData } }
}
And it's within a posts.ts file within a lib/ folder in my root directory. I have also tried running this from the page it is meant to support. Attached is a screenshot of the error I am receiving, and
"Im useful!"
is never logging. Logging the prop from the react page comes up as undefined as well.Any help appreciated. Thanks in advance!
Answered by Black Vulture
I tried it both ways. The answer seems to be that getStaticProps is no longer supported in the new app/ router and should be throwing an error except it just failed silently and never called it.
6 Replies
It is export function getStaticProps not export default function getStaticProps
Black VultureOP
I tried it both ways. The answer seems to be that getStaticProps is no longer supported in the new app/ router and should be throwing an error except it just failed silently and never called it.
Answer
Black VultureOP
Data fetching in the app router docs takes you here: https://nextjs.org/docs/app/building-your-application/data-fetching/fetching
Well that’s your error. In the app router it doesn’t exist so you can’t use it
You have to use server components as described in the linked page
Black VultureOP
yep; I was reading the wrong docs. Didn't realize that anything besides routing changed.