|
1 | | -import React, { useState, useEffect, useRef, ReactText } from "react"; |
| 1 | +import React, { useState, useEffect, useRef, ReactText, Suspense } from "react"; |
2 | 2 | import { useRouteMatch, useHistory } from "react-router-dom"; |
3 | 3 | // eslint-disable-next-line @typescript-eslint/no-unused-vars |
4 | 4 | import type { match } from "react-router-dom"; |
5 | 5 | import { Button, IconButton } from "@material-ui/core"; |
6 | 6 | import { Close as CloseIcon } from "@material-ui/icons"; |
7 | 7 | import { useSnackbar } from "notistack"; |
8 | | -import MapGL, { Popup, Source, Layer, Marker } from "@urbica/react-map-gl"; |
9 | 8 | import { WebMercatorViewport } from "viewport-mercator-project"; |
10 | 9 | import type { WebMercatorViewportOptions } from "viewport-mercator-project"; |
11 | 10 | import { distance as turfDistance } from "@turf/turf"; |
@@ -136,6 +135,12 @@ const fitBounds = ( |
136 | 135 | }; |
137 | 136 |
|
138 | 137 | const App: React.FC = () => { |
| 138 | + const MapGL = React.lazy(() => import("@urbica/react-map-gl")); |
| 139 | + const Popup = React.lazy(async () => {return (await import("@urbica/react-map-gl")).Popup}); |
| 140 | + const Source = React.lazy(async () => {return (await import("@urbica/react-map-gl")).Source}); |
| 141 | + const Layer = React.lazy(async () => {return (await import("@urbica/react-map-gl")).Layer}); |
| 142 | + const Marker = React.lazy(async () => {return (await import("@urbica/react-map-gl")).Marker}); |
| 143 | + |
139 | 144 | // eslint-disable-next-line @typescript-eslint/no-explicit-any |
140 | 145 | const map = useRef<any>(null); |
141 | 146 |
|
@@ -489,7 +494,8 @@ const App: React.FC = () => { |
489 | 494 | ); |
490 | 495 | }} |
491 | 496 | /> |
492 | | - <MapGL |
| 497 | + <Suspense fallback={<div>loading</div>}> |
| 498 | + <MapGL |
493 | 499 | ref={map} |
494 | 500 | // This is according to the Get Started materials: |
495 | 501 | // https://uber.github.io/react-map-gl/docs/get-started/get-started/ |
@@ -707,6 +713,7 @@ const App: React.FC = () => { |
707 | 713 | </Popup> |
708 | 714 | )} |
709 | 715 | </MapGL> |
| 716 | + </Suspense> |
710 | 717 | </div> |
711 | 718 | ); |
712 | 719 | }; |
|
0 commit comments