From 41334eedc3dc70bcb330f10ed56eaba51c61e0e6 Mon Sep 17 00:00:00 2001 From: Jon Thompson Date: Thu, 27 Jun 2019 22:45:00 +0100 Subject: [PATCH] Replace deprecated componentWillReceiveProps with componentDidUpdate --- src/Geographies.js | 10 +++++----- src/Graticule.js | 8 ++++---- src/ZoomableGlobe.js | 10 +++++----- src/ZoomableGroup.js | 12 ++++++------ 4 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/Geographies.js b/src/Geographies.js index 6245298..c4a4723 100644 --- a/src/Geographies.js +++ b/src/Geographies.js @@ -12,13 +12,13 @@ class Geographies extends Component { this.parseGeographies(props.geography) } } - componentWillReceiveProps(nextProps) { - if (nextProps.geography !== this.props.geography) { - if (this.shouldFetchGeographies(nextProps.geography)) { - this.fetchGeographies(nextProps.geography) + componentDidUpdate(prevProps) { + if (prevProps.geography !== this.props.geography) { + if (this.shouldFetchGeographies(prevProps.geography)) { + this.fetchGeographies(prevProps.geography) } else { this.setState({ - geographyPaths: this.parseGeographies(nextProps.geography) + geographyPaths: this.parseGeographies(prevProps.geography) }) } } diff --git a/src/Graticule.js b/src/Graticule.js index bfa86d3..43fa651 100644 --- a/src/Graticule.js +++ b/src/Graticule.js @@ -45,7 +45,7 @@ class Graticule extends Component { : computeOutline(projection), }) } - componentWillReceiveProps(nextProps) { + componentDidUpdate(prevProps) { const { step, projection, @@ -54,12 +54,12 @@ class Graticule extends Component { globe, } = this.props - if (nextProps.round !== round || nextProps.precision !== precision || globe) { + if (prevProps.round !== round || prevProps.precision !== precision || globe) { this.setState({ - graticulePath: nextProps.round + graticulePath: prevProps.round ? roundPath(computeGraticule(projection, step), precision) : computeGraticule(projection, step), - outlinePath: nextProps.round + outlinePath: prevProps.round ? roundPath(computeOutline(projection), precision) : computeOutline(projection), }) diff --git a/src/ZoomableGlobe.js b/src/ZoomableGlobe.js index 8c09a3f..cc47193 100644 --- a/src/ZoomableGlobe.js +++ b/src/ZoomableGlobe.js @@ -85,16 +85,16 @@ class ZoomableGlobe extends Component { evt.preventDefault() } } - componentWillReceiveProps(nextProps) { + componentDidUpdate(prevProps) { const { mouseX, mouseY } = this.state const { projection, center, zoom } = this.props - const zoomFactor = nextProps.zoom / zoom - const centerChanged = JSON.stringify(nextProps.center) !== JSON.stringify(center) + const zoomFactor = prevProps.zoom / zoom + const centerChanged = JSON.stringify(prevProps.center) !== JSON.stringify(center) this.setState({ - zoom: nextProps.zoom, - rotation: centerChanged ? [-nextProps.center[0], -nextProps.center[1], this.state.rotation[2]] : this.state.rotation, + zoom: prevProps.zoom, + rotation: centerChanged ? [-prevProps.center[0], -prevProps.center[1], this.state.rotation[2]] : this.state.rotation, }) } componentDidMount() { diff --git a/src/ZoomableGroup.js b/src/ZoomableGroup.js index 4012dee..367a620 100644 --- a/src/ZoomableGroup.js +++ b/src/ZoomableGroup.js @@ -92,17 +92,17 @@ class ZoomableGroup extends Component { evt.preventDefault() } } - componentWillReceiveProps(nextProps) { + componentDidUpdate(prevProps) { const { mouseX, mouseY, resizeFactorX, resizeFactorY } = this.state const { projection, center, zoom } = this.props - const zoomFactor = nextProps.zoom / zoom - const centerChanged = JSON.stringify(nextProps.center) !== JSON.stringify(center) + const zoomFactor = prevProps.zoom / zoom + const centerChanged = JSON.stringify(prevProps.center) !== JSON.stringify(center) this.setState({ - zoom: nextProps.zoom, - mouseX: centerChanged ? calculateMousePosition("x", nextProps.projection, nextProps, nextProps.zoom, resizeFactorX) : mouseX * zoomFactor, - mouseY: centerChanged ? calculateMousePosition("y", nextProps.projection, nextProps, nextProps.zoom, resizeFactorY) : mouseY * zoomFactor, + zoom: prevProps.zoom, + mouseX: centerChanged ? calculateMousePosition("x", prevProps.projection, prevProps, prevProps.zoom, resizeFactorX) : mouseX * zoomFactor, + mouseY: centerChanged ? calculateMousePosition("y", prevProps.projection, prevProps, prevProps.zoom, resizeFactorY) : mouseY * zoomFactor, }) } handleResize() {