Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Mar 27, 2021. It is now read-only.
This repository was archived by the owner on Mar 27, 2021. It is now read-only.

Stripe async example and README doesn't always load properly #154

@ljbade

Description

@ljbade

We implemented the async Stripe loading following the README and example. However users found that the Stripe form did not always load properly and required a few page refreshes for it to load.

We discovered an improvement that fixes this issue by checking if the script had already finished loading before the component was created. For example if the Stripe form is on another container from the home page.

The change we made was:

  componentDidMount() {
    if (window.Stripe) {
      this.state = { stripe: window.Stripe(this.props.stripeConfig.key) };
    } else {
      document.querySelector('#stripe-js').addEventListener('load', () => {
        this.setState({ stripe: window.Stripe(this.props.stripeConfig.key) });
      });
    }
  }

/cc @tonyd256

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions