我们无法从指定元素检索数据。请确保您尝试使用的元素仍处于安装状态

问题描述 投票:0回答:1

我在将 Stripe 与 React.js 集成时遇到问题。我面临的错误消息是:“我们无法从指定的元素检索数据。请确保您尝试使用的元素仍然已安装。”

以下是相关代码片段:

`// WithStripe Component
import React from "react";
import { useSelector } from "react-redux";
import { Elements } from "@stripe/react-stripe-js";
import { loadStripe } from "@stripe/stripe-js";

function WithStripe({ children }) {
  const { stripeKey } = useSelector((state) => state?.stripeReducer);
  let promise = null;
  if (stripeKey) {
    promise = loadStripe(stripeKey);
  }
  const { language } = useSelector((state) => state?.AppReducer);
  return (
    <Elements
      stripe={promise}
      options={{
        locale: language,
      }}
    >
      {children}
    </Elements>
  );
}

export default WithStripe;

// Entry point
import React, { Suspense } from "react";
import ReactDOM from "react-dom";
import "./index.css";
import App from "./app/Index";
import WithStripe from "components/Hoc/WithStripe";

ReactDOM.render(
  <WithStripe>
    <App />
  </WithStripe>,
  document.getElementById("root")
);`
reactjs stripe-payments stripe-payment-intent
1个回答
0
投票

您能否在问题中包含 Strip 调用方法的代码?

看看这些答案是否能解决您的问题...

Stripe 无法使用错误“未捕获(承诺)错误:我们无法从指定元素检索数据。”

© www.soinside.com 2019 - 2024. All rights reserved.