Search
 
SCRIPT & CODE EXAMPLE
 

TYPESCRIPT

getserversideprops vs getstaticprops

use getServersideProps when data will change after time like wordpress post
which will be changing when new we add new post.
Use getStaticProps when it is static content using it make it cache in.nextjs
so it will load fast.
//Note if you use getStaticProps in dynamic content section then content which 
//is added after deployment will not shown cause it also shown content from cache.
Comment

getserversideprops

export async function getStaticPaths() {
  const res = await fetch(`${baseUrl}/wp-json/wp/v2/posts`)
  const posts = await res.json()
  //paths is array of objects which is contains one params property with id or slug
  const paths = posts.map(({ slug }) => ({ params: { slug: `${slug}` } }))

  return {
    paths,
    //fallback true mean there is no slug in build time then it will not shown 404 error 
    // and fetch data from server and show it
    fallback: true,
  }
}
Comment

PREVIOUS NEXT
Code Example
Typescript :: typescript arr numbers and strings 
Typescript :: jquery select multiple elements with same class 
Typescript :: google sheets mode text 
Typescript :: api service in angular 
Typescript :: dotnet cli sln add all projects 
Typescript :: typescript trim spaces in string array 
Typescript :: common mistakes 
Typescript :: laravel many to many get related posts by category 
Typescript :: wp search post type results page 
Typescript :: replace element in array typescript 
Typescript :: typescript generic dictionary 
Typescript :: react-excel-renderer 
Typescript :: ts Decorator pattern 
Typescript :: typescript variables 
Typescript :: conditional styled components with media query 
Typescript :: typescript type definition 
Typescript :: props vue typescript 
Typescript :: array in typescript 
Typescript :: Custom validation for phone-number using class-validator package 
Typescript :: from how many ways we can define props with typescript react 
Typescript :: copying the contents of a file to another in terminal 
Typescript :: typescript array 
Typescript :: find common elements in two flutter 
Typescript :: display entry count for specific column using value_counts spyder. 
Typescript :: literal types typescript 
Typescript :: accessing the elements of a char* in c 
Typescript :: python remove accents pandas 
Typescript :: how to pring events in pygame 
Typescript :: class in typescript 
Typescript :: typescript document.getelementbyid object is possibly null 
ADD CONTENT
Topic
Content
Source link
Name
2+6 =