Instantly share code, notes, and snippets.

Embed
What would you like to do?
class DateVerifier extends React.Component {
constructor(props) {
super(props)
this.state = {
dob: null
}
}
render() {
return (
<DateInput onDateChange={(val) => this.setState({ dob: value })} />
)
}
}
class DateInput extends React.Component {
constructor(props) {
super(props)
this.state = {
day: null,
month: null,
year: null
}
}
handleInputChange(event) {
const target = event.target
const name = target.name
this.setState({
[name]: target.value
})
}
componentDidUpdate() {
const date = moment([this.state.year, this.state.month, this.state.day]);
this.props.onDateChange(date.format('MM-DD-YYYY'));
}
render() {
return (
<input name="day" onChange={this.handleInputChange.bind(this)} />
<input name="month" onChange={this.handleInputChange.bind(this)} />
<input name="year" onChange={this.handleInputChange.bind(this)} />
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment