小编Aha*_*mii的帖子

Stripe:在 nextjs 中找不到 Elements 上下文错误

我在 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)

stripe-payments reactjs next.js

4
推荐指数
1
解决办法
1451
查看次数

标签 统计

next.js ×1

reactjs ×1

stripe-payments ×1