Skip to content
0:00 / 0:00

#next.js#getserversideprops#getinitialprops

Next.js Tutorial - Part 9 | Data Fetching with getServerSideProps

Bruno Antunes

21K subscribers • 7 videos on Hallway

YouTube

Intermediate. Assumes working knowledge.

35K views6 years ago1 recommendation

Web developmentReactVue, Svelte, Angular and others

An explanation of getServerSideProps and getInitialProps in Next.js using diagrams and code examples.

In this video, we will understand getServerSideProps using code and diagrams! We will look into the differences/similarities between getServerSideProps and getInitialProps. At the end of the video, we will also add NProgress to make our UX a bit better when navigating from page to page. From Next.js documentation: When should I use getServerSideProps? You should use getServerSideProps only if you need to pre-render a page whose data must be fetched at request time. Time to first byte (TTFB) will be slower than getStaticProps because the server must compute the result on every request, and the result cannot be cached by a CDN without extra configuration. If you don’t need to pre-render the data, then you should consider fetching data on the client-side using SWR. ---- Timeline: Presentation Starts Diagram getServerSideProps and getInitialProps - server side Diagram getInitialProps - client side Diagram getServerSideProps - client side without "optimization" Diagram getServerSideProps - client side with "optimization" Diagram getServerSideProps - server side with "optimization" Tweet from Guillermo Rauch (CEO at zeit) Diagram getServerSideProps vs getInitialProps - client side Diagram getServerSideProps vs getInitialProps - server side A question to you all :) Jumping into code!! Create a simple component to print json Create getServerSideProps in that component with database query Create People component to iterate over names Create getServerSideProps in People component Create navigation between the 2 components See the return from getServerSideProps (client side) in the browser Introducing Latency to our getServerSideProps to see the implications Show how GitHub solves that same issue of latency between navigation Introducing NProgress to achieve the same GitHub is achieving Custom _app.tsx Listen to Next.js router events using Router.events.on('event name', handler) Connect NProgress and Next.js Router Events Remove the spinner from NProgress Play with NProgress options Conclusion and thank you!! :) ---- SWR Video: youtu.be/a7JigiLw_OY ---- Presentation URL: docs.google.com/presentation/d/1JfLfLHuyWsqmXZDVSv5_nFFb5AOf… ---- Github Repository: github.com/bmvantunes/youtube-2020-april-nextjs-part9 ---- getInitialProps Video: youtu.be/Os3JZc2CtwY ---- Follow me on: Twitter: twitter.com/bmvantunes Dev.to: dev.to/bmvantunes Website: brunoantunes.net Github: github.com/bmvantunes LinkedIn: linkedin.com/in/bmvantunes

Why it's here

1 person recommends this

What people say. Recommended as a clear explanation of server-side rendering data fetching in Next.js.

u/bmvantunesin r/node • Recommends

getServerSideProps and getInitialProps explained with Diagrams and Code