Skip to content

Commit

Permalink
Rename upcoming deprecated Lifecycle methods (#214)
Browse files Browse the repository at this point in the history
* rename lifecycle methods in src

* update examples

* fix weird prettier stuff
  • Loading branch information
ekh64 authored Jan 29, 2020
1 parent 5fa4310 commit 5044ea0
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 13 deletions.
2 changes: 1 addition & 1 deletion docs/src/docs/PieChart/examples/PieChart.js.example
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class PieChartExample extends React.Component {
this.setState({ sinVal });
};

componentWillMount() {
UNSAFE_componentWillMount() {
this._interval = setInterval(this._animateValue, 20);
}
componentWillUnmount() {
Expand Down
2 changes: 1 addition & 1 deletion docs/src/docs/TreeMap/examples/AnimatedTreeMap.js.example
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class AnimatedTreeMapExample extends React.Component {
this.setState({getValue: "size"});
};

componentWillMount() {
UNSAFE_componentWillMount() {
this._interval = setInterval(this._animateValue, 1000);
this._data = {
children: _.range(1, 5).map(n => ({
Expand Down
4 changes: 2 additions & 2 deletions src/KernelDensityEstimation.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,10 @@ class KernelDensityEstimation extends React.Component {
return shouldUpdate;
}

componentWillMount() {
UNSAFE_componentWillMount() {
this.initKDE(this.props);
}
componentWillReceiveProps(newProps) {
UNSAFE_componentWillReceiveProps(newProps) {
this.initKDE(newProps);
}
initKDE(props) {
Expand Down
6 changes: 4 additions & 2 deletions src/LineChart.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,13 @@ export default class LineChart extends React.Component {
return !xyPropsEqual(this.props, nextProps, ['lineStyle', 'lineClassName']);
}

componentWillMount() {
/* eslint-disable-next-line camelcase */
UNSAFE_componentWillMount() {
this.initBisector(this.props);
}

componentWillReceiveProps(nextProps) {
/* eslint-disable-next-line camelcase */
UNSAFE_componentWillReceiveProps(nextProps) {
this.initBisector(nextProps);
}

Expand Down
6 changes: 4 additions & 2 deletions src/SankeyDiagram.js
Original file line number Diff line number Diff line change
Expand Up @@ -976,11 +976,13 @@ export default class SankeyDiagram extends React.Component {
this._graph = enhanceGraph(sankeyGraph);
}

componentWillMount() {
/* eslint-disable-next-line camelcase */
UNSAFE_componentWillMount() {
this._makeSankeyGraph();
}

componentWillReceiveProps(nextProps) {
/* eslint-disable-next-line camelcase */
UNSAFE_componentWillReceiveProps(nextProps) {
// only update this._graph if a prop which affects the sankey layout has changed (most don't)
const sankeyLayoutPropKeys = [
'nodes',
Expand Down
8 changes: 6 additions & 2 deletions src/TreeMap.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,18 @@ class TreeMap extends React.Component {
NodeComponent: TreeMapNode,
NodeLabelComponent: TreeMapNodeLabel,
};
componentWillMount() {

/* eslint-disable-next-line camelcase */
UNSAFE_componentWillMount() {
const { data } = this.props;
// initialize the layout function
this._tree = getTree(this.props);
// clone the data because d3 mutates it!
this._rootNode = getRootNode(cloneDeep(data), this.props);
}
componentWillReceiveProps(newProps) {

/* eslint-disable-next-line camelcase */
UNSAFE_componentWillReceiveProps(newProps) {
const { width, height, data, sticky } = this.props;

// if height, width, or the data changes, or if the treemap is not sticky, re-initialize the layout function
Expand Down
5 changes: 2 additions & 3 deletions src/ZoomContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,8 @@ export default class ZoomContainer extends React.Component {
if (this.props.onZoom) this.props.onZoom(nextZoomTransform, ...args);
};

// React is deprecating componentWillReceiveProps, but it's pretty much necessary in this case
// TODO: change to UNSAFE_componentWillReceiveProps when upgrading React
componentWillReceiveProps(nextProps) {
/* eslint-disable-next-line camelcase */
UNSAFE_componentWillReceiveProps(nextProps) {
if (this.props.controlled) {
// if controlled component and zoom props have changed, apply the new zoom props to d3-zoom
// (unbind handler first so as not to create infinite callback loop)
Expand Down

0 comments on commit 5044ea0

Please sign in to comment.