DEV Community

Must I use Nextjs Data Fetching Methods?

NJOKU SAMSON EBERE on June 09, 2020

Nextjs is a react-node framework (i.e. it combines reactjs and nodejs so that your project is all in one place). If you have tried Data fetching ...
Collapse
 
jubino87 profile image
Bino Le

Nextjs data fetching methods are used for static and server side rendering. It’s ok to fetch data in componentDidMount or useEffect if you don’t really need static/server side rendering.

Collapse
 
ebereplenty profile image
NJOKU SAMSON EBERE

Thank you Bino. πŸ€—

Is there a way you can enlighten me on this static/server rendering thing?

Like I want to know why it is a better way of doing things

Collapse
 
itsjzt profile image
Saurabh Sharma

It you fetch the data in getInitialProps then your html has the data.

Benefits:

  • it whole purpose of server side rendering
  • better SEO
  • faster website because the client didn't have to wait for react to load, for data loading, and in good cases it can redydrate the cache, so no need to load data on client
Thread Thread
 
ebereplenty profile image
NJOKU SAMSON EBERE

Thank you Saurabh. These benefits sounds so awesome πŸ€—

I will dig more to find out why it’s not working for me πŸ€¦πŸ»β€β™‚οΈπŸ˜Š

Thread Thread
 
itsjzt profile image
Saurabh Sharma

I can't say why it isnt working for you.

But from my debugging experiences in next.js, i will say fetch on server isnt same as fetch on client

Thread Thread
 
ebereplenty profile image
NJOKU SAMSON EBERE

Wow... Any suggestions on what I might have to try out?