MCPcopy
hub / github.com/visgl/react-google-maps / useMapOptions

Function useMapOptions

src/components/map/use-map-options.ts:49–75  ·  view source on GitHub ↗
(map: google.maps.Map | null, mapProps: MapProps)

Source from the content-addressed store, hash-verified

47 * @internal
48 */
49export function useMapOptions(map: google.maps.Map | null, mapProps: MapProps) {
50 /* eslint-disable react-hooks/exhaustive-deps --
51 *
52 * The following effects aren't triggered when the map is changed.
53 * In that case, the values will be or have been passed to the map
54 * constructor via mapOptions.
55 */
56
57 const mapOptions: google.maps.MapOptions = {};
58 const keys = Object.keys(mapProps) as (keyof google.maps.MapOptions)[];
59 for (const key of keys) {
60 if (!mapOptionKeys.has(key)) continue;
61
62 mapOptions[key] = mapProps[key] as never;
63 }
64
65 // update the map options when mapOptions is changed
66 // Note: due to the destructuring above, mapOptions will be seen as changed
67 // with every re-render, so we're assuming the maps-api will properly
68 // deal with unchanged option-values passed into setOptions.
69 useDeepCompareEffect(() => {
70 if (!map) return;
71
72 map.setOptions(mapOptions);
73 }, [mapOptions]);
74 /* eslint-enable react-hooks/exhaustive-deps */
75}

Callers 1

MapFunction · 0.90

Calls 2

useDeepCompareEffectFunction · 0.90
hasMethod · 0.80

Tested by

no test coverage detected