Skip to content

Instantly share code, notes, and snippets.

@indreklasn
Created February 3, 2020 14:24
Show Gist options
  • Save indreklasn/354817b008c55deb56f10f989f580713 to your computer and use it in GitHub Desktop.
Save indreklasn/354817b008c55deb56f10f989f580713 to your computer and use it in GitHub Desktop.
import React from 'react';
import Cards from 'react-credit-cards';
export default class PaymentForm extends React.Component {
state = {
cvc: '',
expiry: '',
focus: '',
name: '',
number: '',
};
handleInputFocus = (e) => {
this.setState({ focus: e.target.name });
}
handleInputChange = (e) => {
const { name, value } = e.target;
this.setState({ [name]: value });
}
render() {
return (
<div id="PaymentForm">
<Cards
cvc={this.state.cvc}
expiry={this.state.expiry}
focused={this.state.focus}
name={this.state.name}
number={this.state.number}
/>
<form>
<input
type="tel"
name="number"
placeholder="Card Number"
onChange={this.handleInputChange}
onFocus={this.handleInputFocus}
/>
...
</form>
</div>
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment