Skip to content

Commit

Permalink
Update state.date when props.selected changes
Browse files Browse the repository at this point in the history
This solves an issue where the calendar wouldn't immediately switch to the correct view when a user types in another date in the input.
  • Loading branch information
RSO committed Jul 4, 2014
1 parent 119adfa commit a17b7f2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
6 changes: 6 additions & 0 deletions react-datepicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ var Calendar = React.createClass({displayName: 'Calendar',
};
},

componentWillReceiveProps: function(nextProps) {
this.setState({
date: nextProps.selected.clone()
});
},

increaseMonth: function() {
this.setState({
date: this.state.date.addMonth()
Expand Down
6 changes: 6 additions & 0 deletions src/calendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ var Calendar = React.createClass({
};
},

componentWillReceiveProps: function(nextProps) {
this.setState({
date: nextProps.selected.clone()
});
},

increaseMonth: function() {
this.setState({
date: this.state.date.addMonth()
Expand Down

0 comments on commit a17b7f2

Please sign in to comment.