Skip to content

Commit

Permalink
fix react lifecycle warning
Browse files Browse the repository at this point in the history
  • Loading branch information
afc163 committed Dec 25, 2019
1 parent 0cabf95 commit eabd866
Showing 1 changed file with 19 additions and 22 deletions.
41 changes: 19 additions & 22 deletions src/month/MonthTable.js
@@ -1,36 +1,23 @@
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import classnames from 'classnames';
import { polyfill } from 'react-lifecycles-compat';
import { getTodayTime, getMonthName } from '../util/index';

const ROW = 4;
const COL = 3;

function chooseMonth(month) {
const next = this.state.value.clone();
next.month(month);
this.setAndSelectValue(next);
}

function noop() {

}
function noop() {}

class MonthTable extends Component {
constructor(props) {
super(props);

this.state = {
value: props.value,
};
}
state = {
};

componentWillReceiveProps(nextProps) {
if ('value' in nextProps) {
this.setState({
value: nextProps.value,
});
static getDerivedStateFromProps(props) {
if ('value' in props) {
return { value: props.value };
}
return null;
}

setAndSelectValue(value) {
Expand All @@ -40,6 +27,12 @@ class MonthTable extends Component {
this.props.onSelect(value);
}

chooseMonth(month) {
const next = this.state.value.clone();
next.month(month);
this.setAndSelectValue(next);
}

months() {
const value = this.state.value;
const current = value.clone();
Expand Down Expand Up @@ -107,7 +100,7 @@ class MonthTable extends Component {
<td
role="gridcell"
key={monthData.value}
onClick={disabled ? null : chooseMonth.bind(this, monthData.value)}
onClick={disabled ? null : () => this.chooseMonth(monthData.value)}
title={monthData.title}
className={classnames(classNameMap)}
>
Expand All @@ -130,10 +123,14 @@ class MonthTable extends Component {
MonthTable.defaultProps = {
onSelect: noop,
};

MonthTable.propTypes = {
onSelect: PropTypes.func,
cellRender: PropTypes.func,
prefixCls: PropTypes.string,
value: PropTypes.object,
};

polyfill(MonthTable);

export default MonthTable;

0 comments on commit eabd866

Please sign in to comment.