Skip to content

Commit

Permalink
fix react state update warning
Browse files Browse the repository at this point in the history
  • Loading branch information
Xiaoji Chen committed Dec 30, 2019
1 parent c71b0d4 commit 104182c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
6 changes: 4 additions & 2 deletions src/components/interactive-map.js
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,10 @@ export default class InteractiveMap extends PureComponent<InteractiveMapProps, S
this._updateInteractiveContext({mapContainer});
}

componentDidUpdate() {
this._setControllerProps(this.props);
}

componentWillUnmount() {
this._eventManager.destroy();
}
Expand Down Expand Up @@ -489,8 +493,6 @@ export default class InteractiveMap extends PureComponent<InteractiveMapProps, S
};

render() {
this._setControllerProps(this.props);

const {width, height, style, getCursor} = this.props;

const eventCanvasStyle = Object.assign({position: 'relative'}, style, {
Expand Down
3 changes: 2 additions & 1 deletion src/mapbox/mapbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ const defaultProps = {
latitude: 0,
zoom: 0,
bearing: 0,
pitch: 0
pitch: 0,
altitude: 1.5
};

type MapboxGL = {
Expand Down
10 changes: 6 additions & 4 deletions src/utils/map-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ export default class MapController {
/* Callback util */
// formats map state and invokes callback function
updateViewport(newMapState: MapState, extraProps: any = {}, extraState: any = {}) {
const oldViewport = this.mapState ? this.mapState.getViewportProps() : {};
const oldViewport = this.mapState ? this.mapState.getViewportProps() : this.mapStateProps;
const newViewport = Object.assign({}, newMapState.getViewportProps(), extraProps);

const viewStateChanged = Object.keys(newViewport).some(
Expand Down Expand Up @@ -176,12 +176,14 @@ export default class MapController {
this.onViewportChange = onViewportChange;
this.onStateChange = onStateChange;

if (!this.mapStateProps || this.mapStateProps.height !== options.height) {
const dimensionChanged = !this.mapStateProps || this.mapStateProps.height !== options.height;

this.mapStateProps = options;

if (dimensionChanged) {
// Dimensions changed, normalize the props
this.updateViewport(new MapState(options));
}

this.mapStateProps = options;
// Update transition
this._transitionManager.processViewportChange(
Object.assign({}, options, {
Expand Down

0 comments on commit 104182c

Please sign in to comment.