Skip to content

Instantly share code, notes, and snippets.

@dapperAuteur
Created September 27, 2019 00:47
Show Gist options
  • Save dapperAuteur/ce45192b1f858049aca5490327cb4f7d to your computer and use it in GitHub Desktop.
Save dapperAuteur/ce45192b1f858049aca5490327cb4f7d to your computer and use it in GitHub Desktop.
stripe skus
import React, { Component } from "react"
import { graphql, StaticQuery } from "gatsby"
import SkuCard from "./SkuCard"
const containerStyles = {
display: "flex",
flexDirection: "row",
flexWrap: "wrap",
justifyContent: "space-between",
padding: "1rem 0 1rem 0",
}
class Skus extends Component {
state = {
stripe: null,
}
componentDidMount() {
const stripe = window.Stripe(process.env.GATSBY_STRIPE_PUBLIC_KEY)
this.setState({ stripe })
console.log("stripe", stripe)
}
render() {
return (
<StaticQuery
query={graphql`
query SkusForProduct {
skus: allStripeSku {
edges {
node {
id
currency
price
attributes {
name
}
}
}
}
}
`}
render={({ skus }) => (
<div style={containerStyles}>
{skus.edges.map(({ node: sku }) => {
console.log("skus", skus)
return (
<SkuCard key={sku.id} sku={sku} stripe={this.state.stripe} />
)
})}
</div>
)}
/>
)
}
}
export default Skus
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment