question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Documentation needs to mention writing server-side code in GS(S)P props earlier

See original GitHub issue

Lots of users miss that they can write server side code in getStaticProps and getServerSideProps.

We also see numerous issues about people trying to fetch API routes. We need to fix this in the documentation by making this one of the first things we have in the docs.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
adriancooneycommented, Sep 6, 2020

Throwing my opinion down here - I don’t think this is fixed. I found this issue via blame’ing the note in the docs because it confused me even further. Why can we not fetch API routes? This has broken my mental model of how Next.js used to work (i.e. fetch from API during SSR).

Two notes on the content of the fix:

Instead, directly import the API route and call its function yourself.

How do we call the function itself? How do we access the data? Do you mean repeat the data fetching (i.e. DB calls) in the API route in the getServerSideProps method? I think I’m misunderstanding something here.

You may need to slightly refactor your code for this approach.

Without any indication how to approach this refactor or what the refactor entails makes for a pretty frustrating read. I think pointing to an example here of an app using API routes in SSR would be really useful. I’m currently lost and regretting my decision to use API routes because of the complexity and hidden constraints.

1reaction
agarwalrounakcommented, Aug 12, 2020

I will take this up.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Server Side Render Dynamic Page based on Route Param
I don't want to call api and get the data using useEffect inside the component. File: pages/post/[code].js import React from 'react'; import ...
Read more >
Data Fetching: getServerSideProps - Next.js
Pages using getServerSideProps will be server side rendered at request time and only be cached if cache-control headers are configured. If you do...
Read more >
Using Queries - Blitz.js
In a React Component. To use one of your Blitz queries, call the useQuery hook with: Your query resolver; The input arguments for...
Read more >
Known Incompatibilities with Previous Releases ... - Documentation
In MarkLogic 10, when you write documents with the REST API using PUT v1/documents, the documents have the union of the following permissions:....
Read more >
Fetch props directly from the Database?!?! New Hooks in Next ...
Next.js 9.3 came out with 3 new hooks that allow you to fetch data in different ways: - getServerSideProps: Fetch data server side...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found