Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

Next / Sanity SSR client fetch

export const getStaticPaths = async () => {
  const query = `*[_type == "product"] {
    slug {
      current
    }
  }`

  const products = await client.fetch(query)
  const paths = products.map((product) => ({
    params: {
      slug: product.slug.current,
    },
  }))

  return {
    paths,
    fallback: 'blocking',
  }
}

export const getStaticProps = async ({ params: { slug } }) => {
  const query = `*[_type == "product" && slug.current == '${slug}'][0]`
  const productsQuery = '*[_type == "product"]'

  const product = await client.fetch(query)
  const products = await client.fetch(productsQuery)

  return {
    props: {
      product,
      products,
    },
  }
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: React Native - iOS Release build crashing 
Javascript :: react antd modal with quill 
Javascript :: ...args javascript 
Javascript :: javascript palindrome check 
Javascript :: cookie in Auth header 
Javascript :: 20 most common question in javascript 
Javascript :: how to broadcast to the entire room scket io 
Javascript :: Joi conditional validation refer parent object 
Javascript :: If you wish to set a method equal to another method in the class 
Javascript :: true type of javascript 
Javascript :: isPowerOfTow 
Javascript :: Get year from user entered date in javascript 
Javascript :: PostManDocs 
Javascript :: var countdown = function(num) {} 
Javascript :: Backbone Model And Collection 
Javascript :: Backbone Set Model In View 
Javascript :: country select dropdown javascript 
Javascript :: how to convert javascript to typescript 
Javascript :: remove duplicate node 
Javascript :: password generator and password strength using javascript 
Javascript :: redirect in react-router-dom v6 
Javascript :: hello world js 
Javascript :: sort list in javascript 
Javascript :: how to make a discord bot delete messages after time js 
Javascript :: moment js get last week start and end date 
Javascript :: oridnal suffix 
Javascript :: vue__WEBPACK_IMPORTED_MODULE_0__.reactive) 
Javascript :: javascript include too large or too small numbers 
Javascript :: xhr.upload 
Javascript :: nuxt login with google strategie 
ADD CONTENT
Topic
Content
Source link
Name
8+3 =