Skip to content

Instantly share code, notes, and snippets.

@siakaramalegos
Last active March 1, 2018 22:38
Show Gist options
  • Save siakaramalegos/140f0b3b467b8b6daddabd10c75cc5b3 to your computer and use it in GitHub Desktop.
Save siakaramalegos/140f0b3b467b8b6daddabd10c75cc5b3 to your computer and use it in GitHub Desktop.
Displaying Card Errors with React Stripe Elements
import React, { Component } from 'react';
import { CardElement } from 'react-stripe-elements';
import isEmpty from 'lodash/isEmpty';
class CreditCardInput extends Component {
constructor() {
super()
this.state = { error: undefined }
}
onCardChange = (e) => {
this.setState({ error: e.error })
}
render() {
return (
<label>
Card info
<CardElement onChange={this.onCardChange} />
{!isEmpty(this.state.error) &&
<span id="card-errors" role="alert">{this.state.error.message}</span>}
</label>
)
}
}
export default CreditCardInput
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment