我在 nextjs 12 中使用 stripe 下面的包
import { loadStripe } from "@stripe/stripe-js";
import { Elements } from "@stripe/react-stripe-js";
Run Code Online (Sandbox Code Playgroud)
它在开发模式下运行良好,但在生产构建时会抛出此错误
Error: Could not find Elements context; You need to wrap the part of your app that calls useStripe() in an <Elements> provider.
Run Code Online (Sandbox Code Playgroud)
我使用 Elements 作为父容器,并使用 Elements 内的 Checkoutform 作为子容器
import React from 'react'
import { useAppContext } from '@/context/AppContext';
import { loadStripe } from "@stripe/stripe-js";
import { Elements } from "@stripe/react-stripe-js";
import Checkoutform from './Checkoutform';
import AppLoader from '@/components/common/Loader';
const Payment …Run Code Online (Sandbox Code Playgroud)