Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

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
Source by nextjs.org #
 
PREVIOUS NEXT
Tagged: #nextjs #getserversideprops
ADD COMMENT
Topic
Name
4+2 =