componentDidUpdate()

in src/ZoomContainer.js [153:177]


  componentDidUpdate(prevProps) {
    const nextProps = this.props;
    if (prevProps.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)
      const hasChangedZoom =
        nextProps.zoomX !== prevProps.zoomX ||
        nextProps.zoomY !== prevProps.zoomY ||
        nextProps.zoomScale !== prevProps.zoomScale;

      if (hasChangedZoom) {
        this.zoom.on('zoom', null);
        const nextZoomTransform = zoomTransformFromProps(nextProps);
        this.zoom.transform(this.state.selection, nextZoomTransform);
        this.zoom.on('zoom', this.handleZoom);

        // update state.lastZoomTransform so we can revert d3-zoom to this next time it's changed internally
        // eslint-disable-next-line react/no-did-update-set-state
        this.setState({
          lastZoomTransform: nextZoomTransform,
        });
      }
    }
    this._updateZoomProps(nextProps);
  }