Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,7 @@
"node": true,
"es6": true
},
"rules": {
"react/no-unused-prop-types": [2, {skipShapeProps: true}]
}
}
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# Change Log

## 1.8.0

* Fixing lint, adding skip shape props.


## 1.7.0

* Fixing shortcut button class.
* Fixing styles.

## 1.6.0

* Adding position proptype.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-monthrange-picker",
"version": "1.6.0",
"version": "1.8.0",
"description": "ReactJS Month range picker",
"main": "index.js",
"scripts": {
Expand Down
28 changes: 28 additions & 0 deletions src/app.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ require('moment-range');
class App extends React.Component {
constructor(props) {
super(props);
this.redraw = props.redraw || false;
this.handleClickFn = this.handleClick.bind(this);
this.onSelectFn = this.onSelect.bind(this);
this.onApplyFn = this.onApply.bind(this);
Expand All @@ -18,6 +19,28 @@ class App extends React.Component {
this.state = { selectedDateRange, restrictionRange, display };
this.selectedDateRange = selectedDateRange.clone();
}
componentWillReceiveProps(props) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jasonkobilka there are multiple componentWillReceiveProps fn

this.selectedDateRange = props.selectedDateRange.clone();
const sameDates = this.props.selectedDateRange.isSame(props.selectedDateRange);

// update state only if props are different, OR if forced
if(this.redraw || !sameDates) {
console.log('setting state to redraw', this.selectedDateRange.end.toString());
this.state.selectedDateRange = this.selectedDateRange.clone();
this.setState(this.state);
} else {
console.log('blocking redraw');
}
}
componentWillReceiveProps(props) {
this.selectedDateRange = props.selectedDateRange.clone();
const sameDates = this.props.selectedDateRange.isSame(props.selectedDateRange);
// update state only if props are different, OR if forced
if(this.redraw || !sameDates) {
this.state.selectedDateRange = this.selectedDateRange.clone();
this.setState(this.state);
}
}
componentDidMount() {
if (this.props.onRender) {
this.props.onRender();
Expand Down Expand Up @@ -49,6 +72,11 @@ class App extends React.Component {
}
this.setState(this.state);
}
syncData() {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

syncing var happens in the componentwillreceiveprops no need for explicit assignment.

// force a redraw by setting state
this.state.selectedDateRange = this.selectedDateRange.clone();
this.setState(this.state);
}
handleClick(e) {
e.preventDefault();
e.stopPropagation();
Expand Down