Skip to content

Commit 9cbab09

Browse files
committed
feat(Tree): upgrade life circle
1 parent 8d3b25d commit 9cbab09

File tree

2 files changed

+309
-249
lines changed

2 files changed

+309
-249
lines changed

src/tree/view/tree-node.jsx

+14-9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React, { Component, Children } from 'react';
22
import { findDOMNode } from 'react-dom';
33
import PropTypes from 'prop-types';
4+
import { polyfill } from 'react-lifecycles-compat';
45
import cx from 'classnames';
56
import Icon from '../../icon';
67
import Checkbox from '../../checkbox';
@@ -16,7 +17,7 @@ const isRoot = pos => /^0-(\d)+$/.test(pos);
1617
/**
1718
* Tree.Node
1819
*/
19-
export default class TreeNode extends Component {
20+
class TreeNode extends Component {
2021
static propTypes = {
2122
_key: PropTypes.string,
2223
prefix: PropTypes.string,
@@ -109,19 +110,21 @@ export default class TreeNode extends Component {
109110
]);
110111
}
111112

113+
static getDerivedStateFromProps(props) {
114+
if ('label' in props) {
115+
return {
116+
label: props.label,
117+
};
118+
}
119+
120+
return null;
121+
}
122+
112123
componentDidMount() {
113124
this.itemNode = findDOMNode(this.refs.node);
114125
this.setFocus();
115126
}
116127

117-
componentWillReceiveProps(nextProps) {
118-
if ('label' in nextProps) {
119-
this.setState({
120-
label: nextProps.label,
121-
});
122-
}
123-
}
124-
125128
componentDidUpdate() {
126129
this.setFocus();
127130
}
@@ -593,3 +596,5 @@ export default class TreeNode extends Component {
593596
);
594597
}
595598
}
599+
600+
export default polyfill(TreeNode);

0 commit comments

Comments
 (0)