I'm learning React and want to make an input with two constraints:
- 16 numbers,
- put a space after every fourth.
import React, { Component } from 'react';
export default class CardNumberInput extends Component {
constructor() {
super();
this.state = { value: '' };
}
handleChange(event) {
React.findDOMNode(this.refs.cardInput).mask("0000 0000 0000 0000");
this.setState({ value: event.target.value });
}
render() {
let value = this.state.value;
return (
<div>
<label htmlFor="cardInput">Card Number: </label>
<input ref="cardInput" id="cardInput" onChange={this.handleChange} type="number" value={value} />
</div>
);
}
}
I don't know whether I'm doing it right (use refs), because console.log(React.findDOMNode(this.refs.cardInput)) returns null o_O
p.s. .mask is from http://igorescobar.github.io/jQuery-Mask-Plugin/
findDOMNode
is coming back null, but you should be able to just useevent.target
in place of that ref.