Created
August 16, 2017 05:41
-
-
Save bholzer/194e84ae7a1b0432366c3ad700f76f49 to your computer and use it in GitHub Desktop.
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
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