Skip to content

Commit c0301f3

Browse files
Sechordamfazekas
andauthored
fix: migrate MapView from UNSAFE_componentWillReceiveProps to componentDidUpdate (#3935)
* fix: migrate MapView from UNSAFE_componentWillReceiveProps to componentDidUpdate * refactor: deduplicate callback prop keys using const assertion pattern * Apply suggestions from code review Remove unnecessary code comments --------- Co-authored-by: Miklós Fazekas <mfazekas@szemafor.com>
1 parent 4b9ab15 commit c0301f3

File tree

1 file changed

+31
-20
lines changed

1 file changed

+31
-20
lines changed

src/components/MapView.tsx

Lines changed: 31 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -445,24 +445,27 @@ type Props = ViewProps & {
445445
_nativeImpl?: NativeMapViewActual;
446446
};
447447

448-
type CallbablePropKeys =
449-
| 'onRegionWillChange'
450-
| 'onRegionIsChanging'
451-
| 'onRegionDidChange'
452-
| 'onUserLocationUpdate'
453-
| 'onWillStartLoadingMap'
454-
| 'onMapLoadingError'
455-
| 'onDidFinishLoadingMap'
456-
| 'onDidFailLoadingMap'
457-
| 'onWillStartRenderingFrame'
458-
| 'onDidFinishRenderingFrame'
459-
| 'onDidFinishRenderingFrameFully'
460-
| 'onWillStartRenderingMap'
461-
| 'onDidFinishRenderingMap'
462-
| 'onDidFinishRenderingMapFully'
463-
| 'onDidFinishLoadingStyle'
464-
| 'onMapIdle'
465-
| 'onCameraChanged';
448+
const CallbablePropKeys = [
449+
'onRegionWillChange',
450+
'onRegionIsChanging',
451+
'onRegionDidChange',
452+
'onUserLocationUpdate',
453+
'onWillStartLoadingMap',
454+
'onMapLoadingError',
455+
'onDidFinishLoadingMap',
456+
'onDidFailLoadingMap',
457+
'onWillStartRenderingFrame',
458+
'onDidFinishRenderingFrame',
459+
'onDidFinishRenderingFrameFully',
460+
'onWillStartRenderingMap',
461+
'onDidFinishRenderingMap',
462+
'onDidFinishRenderingMapFully',
463+
'onDidFinishLoadingStyle',
464+
'onMapIdle',
465+
'onCameraChanged',
466+
] as const;
467+
468+
type CallbablePropKeys = typeof CallbablePropKeys[number];
466469

467470
type CallbablePropKeysWithoutOn = CallbablePropKeys extends `on${infer C}`
468471
? C
@@ -570,8 +573,16 @@ class MapView extends NativeBridgeComponent(
570573
this.logger.stop();
571574
}
572575

573-
UNSAFE_componentWillReceiveProps(nextProps: Props) {
574-
this._setHandledMapChangedEvents(nextProps);
576+
componentDidUpdate(prevProps: Props) {
577+
const callbackProps = CallbablePropKeys;
578+
579+
const hasCallbackPropsChanged = callbackProps.some(
580+
propName => prevProps[propName] !== this.props[propName]
581+
);
582+
583+
if (hasCallbackPropsChanged) {
584+
this._setHandledMapChangedEvents(this.props);
585+
}
575586
}
576587

577588
_setHandledMapChangedEvents(props: Props) {

0 commit comments

Comments
 (0)