chargebee-js-wrappers icon indicating copy to clipboard operation
chargebee-js-wrappers copied to clipboard

Error: Component not found

Open MrCookiez opened this issue 2 years ago • 1 comments

Error: Component not found

Description

Then using the chargebee-js-react-wrapper components there is an error occurred when filling the form fields.

Error message: Screenshot 2023-02-24 at 17 41 36

Code implementation:

export const initChargebee = () => {
    window.Chargebee.init({
      site: xxx,
      publishableKey: xxx,
    });
};

import React, { useState, useEffect, useRef } from "react";
import { CardComponent, CardNumber, CardExpiry, CardCVV } from "@chargebee/chargebee-js-react-wrapper";

...

const CardFormComponent = () => {
  const cardRef = useRef();

 // ... initChargebee ...
  
  return (
    <form>
      <CardComponent ref={cardRef}
        styles={options.style}
        classes={options.classes}
        locale="en"
        placeholder={options.placeholder}
      >
        <div className="class1">
          <CardNumber />
        </div>

        <div className="class2">
          <div className="class1">
            <CardExpiry />
          </div>

          <div className="class1">
            <CardCVV />
          </div>
        </div>

        <button onClick={onSubmit}>
          Submit
        </button>
      </CardComponent>
    </form>
  )
}

...

MrCookiez avatar Feb 24 '23 17:02 MrCookiez

I also get the same issue. However, trying to debug this made me realise that the problem doesn't lie with this library or even Chargebee itself, but with trying to initialise it more than once.

Have a look for the following message in the console logs:

Chargebee.js has been already initialized

If you can see it, eliminating repetitive initialisations should fix the issue.

Dremora avatar Jul 18 '23 17:07 Dremora