エラー内容は
PropertyTypeError: Invalid value with type "undefined" was received for stripe. Valid type for stripe is "string".
handleSubmitを実行すると上のような文章が出てしまう
import React, { useState } from "react"
import { useShoppingCart } from 'use-shopping-cart'
...
const handleSubmit = async event => {
event.preventDefault()
setLoading(true)
// price_id
const price = new FormData(event.target).get("priceSelect")
const { error } = await checkoutSingleItem(price)
if (error) {
setLoading(false)
}
}
use-shopping-cartの設定はpages/_app.js
import { getGlobalData } from '../utils/global-data';
import '../styles/globals.css';
import 'prismjs/themes/prism-tomorrow.css';
import { CartProvider } from 'use-shopping-cart'
function MyApp({ Component, pageProps }) {
const globalData = getGlobalData()
return (
<>
<CartProvider
mode={"payment"}
cartMode={"client-only"}
stripe={process.env.NEXT_STRIPE_PUBLISHABLE_KEY}
successUrl={`${globalData.siteUrl}/checkout-success`}
cancelUrl={`${globalData.siteUrl}/cart`}
currency={'jpy'}
>
<span className="theme-bejamas" />
<Component {...pageProps} />
</CartProvider>
</>
);
}
export default MyApp;
...
.envでブラウザに読み込ませたいキーはNEXT_PUBLIC_
をつけないといけなかった
NEXT_STRIPE_PUBLISHABLE_KEY='...'
↓
NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY='...'