Skip to content

Instantly share code, notes, and snippets.

@kianaditya
Created August 30, 2019 08:12
Show Gist options
  • Save kianaditya/7c68e123ca95e88e186b7c9841c5c44e to your computer and use it in GitHub Desktop.
Save kianaditya/7c68e123ca95e88e186b7c9841c5c44e to your computer and use it in GitHub Desktop.
Lifecycle method for stripe elements
componentDidMount() {
if (window.Stripe) {
this.setState({stripe: window.Stripe('pk_test_12345')});
} else {
document.querySelector('#stripe-js').addEventListener('load', () => {
// Create Stripe instance once Stripe.js loads
this.setState({stripe: window.Stripe('pk_test_12345')});
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment