Giter Club home page Giter Club logo

Comments (4)

kevinrenskers avatar kevinrenskers commented on June 16, 2024 2

I think the types don't really make sense?

export interface PayPalNamespace {
    Buttons?: (
        options?: PayPalButtonsComponentOptions,
    ) => PayPalButtonsComponent;
    Marks?: (options?: PayPalMarksComponentOptions) => PayPalMarksComponent;
    Messages?: (
        options?: PayPalMessagesComponentOptions,
    ) => PayPalMessagesComponent;
    HostedFields?: PayPalHostedFieldsComponent;
    getFundingSources?: getFundingSources;
    isFundingEligible?: isFundingEligible;
    rememberFunding?: rememberFunding;
    FUNDING?: Record<string, FUNDING_SOURCE>;
    version: string;
}

Why is Buttons optional?

This makes the error go away but this shouldn't be necessary I would think? Or if it is, then the README should be updated at the very least?

if (paypal && paypal.Buttons) {
  try {
    await paypal.Buttons().render("#your-container-element");
  } catch (error) {
    console.error("failed to render the PayPal Buttons", error);
  }
}

Another way to get rid of the error:

if (paypal) {
  try {
    await paypal.Buttons?.().render("#your-container-element");
  } catch (error) {
    console.error("failed to render the PayPal Buttons", error);
  }
}

Notice the added ?. before the function call.

from paypal-js.

wsbrunson avatar wsbrunson commented on June 16, 2024

@kevinrenskers Technically any component on the global paypal object is optional. In your loadScript you aren't passing components which means by default we are including the buttons component.

If you were using CardFields or Messages though, those components wouldn't exist on paypal since the components weren't loaded.

Or if you had components: ['card-fields'], then Buttons wouldn't exist on paypal since the buttons component wasn't loaded.

We'll discuss this internally though, it may make sense to make all components on the paypal object required and rely on runtime errors/messaging to tell the developer that the component does not exist on the paypal object.

from paypal-js.

kevinrenskers avatar kevinrenskers commented on June 16, 2024

I think it's fine it's optional, but then the example code should deal with this?

from paypal-js.

wsbrunson avatar wsbrunson commented on June 16, 2024

Possibly, we will take a look. I'm wondering if there's a way to keep these optional but also not make every developer using TypeScript have to null check for each component. I guess it is technically safer, if for some reason a component didn't load, it would keep the PayPal JS SDK from taking down the rest of your web page.

We appreciate you bringing this up though!

from paypal-js.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.