File tree Expand file tree Collapse file tree 1 file changed +8
-18
lines changed
Expand file tree Collapse file tree 1 file changed +8
-18
lines changed Original file line number Diff line number Diff line change @@ -69,37 +69,27 @@ const GoogleMapProvider = (props: GoogleMapProviderProps): JSX.Element => {
6969 new GoogleMap ( mapOptions ) ;
7070 } ;
7171
72- // Initializes map on mount
73- useEffect ( ( ) => {
74- if ( ! mapContainer ) {
75- return ( ) : void => { } ;
76- }
77-
78- // create new map instance
79- createGoogleMap ( ) ;
80-
81- // Destroy Google Map when component unmounts
82- return ( ) : void => {
83- map && map . destroyComplete ( ) ;
84- } ;
85- } , [ ] ) ;
72+ // Destroy Google Map when component unmounts
73+ useEffect ( ( ) => map && map . destroyComplete ( ) , [ ] ) ;
8674
8775 // Destroy and recreate map on mapcontainer change
8876 useEffect ( ( ) => {
89- if ( ! map || ! mapContainer ) {
77+ if ( ! mapContainer ) {
9078 return ;
9179 }
9280
93- // Destroy old map instance listeners
94- map . destroyListeners ( ) ;
81+ if ( map ) {
82+ // Destroy old map instance listeners
83+ map . destroyListeners ( ) ;
84+ }
9585
9686 // create new map instance
9787 createGoogleMap ( ) ;
9888 } , [ mapContainer ] ) ;
9989
10090 // Destroy and recreate map on language or region change
10191 useEffect ( ( ) => {
102- if ( ! map || ! mapContainer ) {
92+ if ( ! map ) {
10393 return ;
10494 }
10595
You can’t perform that action at this time.
0 commit comments