Skip to content

Commit 7d7948d

Browse files
author
Martijn Russchen
committed
Merge pull request #11 from Hacker0x01/update-state-on-props-change
Update state.date when props.selected changes
2 parents be07fe9 + a17b7f2 commit 7d7948d

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

react-datepicker.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ var Calendar = React.createClass({displayName: 'Calendar',
1010
};
1111
},
1212

13+
componentWillReceiveProps: function(nextProps) {
14+
this.setState({
15+
date: nextProps.selected.clone()
16+
});
17+
},
18+
1319
increaseMonth: function() {
1420
this.setState({
1521
date: this.state.date.addMonth()

src/calendar.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ var Calendar = React.createClass({
99
};
1010
},
1111

12+
componentWillReceiveProps: function(nextProps) {
13+
this.setState({
14+
date: nextProps.selected.clone()
15+
});
16+
},
17+
1218
increaseMonth: function() {
1319
this.setState({
1420
date: this.state.date.addMonth()

0 commit comments

Comments
 (0)