(map: google.maps.Map | null, mapProps: MapProps)
| 47 | * @internal |
| 48 | */ |
| 49 | export 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 | } |
no test coverage detected