【问题标题】:"Error zoid destroyed all components" error in reactJSreactJS中的“错误zoid破坏了所有组件”错误
【发布时间】:2022-01-25 16:09:44
【问题描述】:

我在电子商务市场上工作,代码似乎没问题,但 paypal 按钮似乎首先在加载时呈现,但在 4-5 秒后消失。控制台显示“未处理的错误错误:zoid 破坏了所有组件”。我已经尝试更换浏览器,但问题仍然存在。 以下是我的代码:

  useEffect(() => {
    const addPaypalScript = async () => {
      const { data: clientId } = await axios.get(
        `/api/config/paypal/${orderId}`
      )
      const script = document.createElement('script')
      script.type = 'text/javascript'
      script.src = `https://www.paypal.com/sdk/js?client-id=${clientId}`
      script.async = true
      script.onload = () => {
        setSdkReady(true)
      }
      document.body.appendChild(script)
    }
    addPaypalScript()
    if (!order || successPay) {
      dispatch({ type: ORDER_PAY_RESET })
      dispatch(getOrderDetails(orderId))
    } else if (!order.isPaid) {
      if (!window.paypal) {
        addPaypalScript()
      } else {
        setSdkReady(true)
      }
    }
  }, [dispatch, orderId, successPay, order])

下面是paypal按钮前端代码

<ListGroup.Item>
                  <Row>
                    {loadingPay && <Loader />}
                    {!sdkReady ? (
                      <Loader />
                    ) : (
                      <PayPalButton
                        onButtonReady={() => setSdkReady(true)}
                        amount={order.totalPrice}
                        onSuccess={successPaymentHandler}
                      />
                    )}
                  </Row>
                </ListGroup.Item>

【问题讨论】:

    标签: javascript reactjs paypal sdk paypal-sandbox


    【解决方案1】:

    对于 react 中的 PayPal 按钮,使用官方的 react-paypal-js 包来处理加载脚本和渲染按钮。

    这里是the documentation with a sample

    【讨论】:

    • 谢谢分享!我能够调试我的代码。原来我添加了两次贝宝脚本,这就是 zoid 销毁所有组件的原因
    猜你喜欢
    • 2020-08-29
    • 2020-04-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-24
    • 2015-10-25
    • 2015-02-19
    相关资源
    最近更新 更多