“GetServerSideprops di NextJS” Kode Jawaban

JS berikutnya GetServerSideprops

export async function getServerSideProps(context) {
  return {
    props: {}, // will be passed to the page component as props
  }
}
Funny Fox

NextJs getServerSideprops

function Page({ data }) {
  // Render data...
}

// This gets called on every request
export async function getServerSideProps() {
  // Fetch data from external API
  const res = await fetch(`https://.../data`)
  const data = await res.json()

  // Pass data to the page via props
  return { props: { data } }
}

export default Page
S3NS4

GetServerSideprops di NextJS

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,
  }
}
Shirshak kandel

Jawaban yang mirip dengan “GetServerSideprops di NextJS”

Pertanyaan yang mirip dengan “GetServerSideprops di NextJS”

Lebih banyak jawaban terkait untuk “GetServerSideprops di NextJS” di TypeScript

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya