Skip to content

Commit

Permalink
Merge pull request #11 from Hacker0x01/update-state-on-props-change
Browse files Browse the repository at this point in the history
Update state.date when props.selected changes
  • Loading branch information
Martijn Russchen committed Jul 4, 2014
2 parents be07fe9 + a17b7f2 commit 7d7948d
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 7d7948d

Please sign in to comment.