From 01cec2868b703c25275765fe70a2fd44ec0a6750 Mon Sep 17 00:00:00 2001 From: Russell Knight <13390184+russell-knight@users.noreply.github.com> Date: Wed, 19 Jun 2024 14:50:57 +1000 Subject: [PATCH] ensure dispatcher and methods are defined before calling them --- src/google_map_markers.js | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/google_map_markers.js b/src/google_map_markers.js index c0389249..88c06a21 100644 --- a/src/google_map_markers.js +++ b/src/google_map_markers.js @@ -96,10 +96,21 @@ export default class GoogleMapMarkers extends Component { this.dimensionsCache_ = {}; } - _getState = () => ({ - children: this.props.dispatcher.getChildren(), - updateCounter: this.props.dispatcher.getUpdateCounter(), - }); + _getState = () => { + let children = []; + let updateCounter = 0; + + if (this.props.dispatcher.getChildren) { + children = this.props.dispatcher.getChildren(); + } + if (this.props.dispatcher.getUpdateCounter) { + this.props.dispatcher.getUpdateCounter(); + } + return { + children, + updateCounter, + }; + }; _onChangeHandler = () => { if (!this.dimensionsCache_) {