Skip to content

Instantly share code, notes, and snippets.

@fsgreco
Created July 15, 2020 16:06
Show Gist options
  • Save fsgreco/38227d2d43d2d8714cc7e49431ddcc77 to your computer and use it in GitHub Desktop.
Save fsgreco/38227d2d43d2d8714cc7e49431ddcc77 to your computer and use it in GitHub Desktop.
products.js component with the new Stripe API v3
import React from 'react'
import { graphql, StaticQuery } from 'gatsby'
import Product from './product.js'
const PRODUCTS_QUERY = graphql`
query allProducts {
allStripePrice(filter: {active: {eq: true}}) {
edges {
node {
nickname
unit_amount
id
product {
id
}
}
}
}
allStripeProduct(filter: {active: {eq: true}}) {
edges {
node {
id
name
images
}
}
}
}
`
const Products = () => (
<StaticQuery query={PRODUCTS_QUERY} render={
data => {
const { allStripePrice, allStripeProduct } = data
return allStripeProduct.edges.map( ({node}) => {
const productId = node.id
const priceVariation = allStripePrice.edges.filter(({ node }) => productId === node.product.id )
return (
<Product key={node.id}
item={node}
prices={priceVariation}
/>
)
})
}
}
/>
)
export default Products
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment