From the course: Master Next.js: Elaborate Hands-On Web Development, React Basics, Advanced Next.js, and Deployment

Unlock this course with a free trial

Join today to access over 25,200 courses taught by industry experts.

When to use GetStaticPropsServer with Next.js

When to use GetStaticPropsServer with Next.js

Before we move on, we built a Markdown-based parsing algorithm. So we were just reading files with readdir sync. But if we were fetching asynchronously from our API, then we would want to use this await async pattern. And we would use something like fetch, which actually Next.js polyfills fetch for us. So you don't need to even import it, which is great. It just means that it's available for us in Next.js. But this is basically, you know, if you wanted to get sorted post data, instead of the file system, you fetch post data from an external API endpoint, you wait for the response, and then you return that response. You could also query a database directly. How would that look? Well, let's zoom out. One in doubt. So let's say we have some database SDK. So you bring in that library, create the client, and then you would run the query, select the posts and do whatever you'd want to do from the SDK. Now, of course, how do you figure out how to do that? Well, you got to go into the…

Contents