Last active
March 1, 2018 22:38
-
-
Save siakaramalegos/140f0b3b467b8b6daddabd10c75cc5b3 to your computer and use it in GitHub Desktop.
Displaying Card Errors with React Stripe Elements
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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