The GeoJsonDataSource, KmlDataSource, and CzmlDataSource components support React Suspense. By passing the suspense prop, these components will trigger a Suspense boundary while fetching data if the data prop is a URL or a Cesium Resource.
When suspense is enabled:
- A parent
<Suspense> component's fallback will be displayed during the fetch. - A parent Error Boundary will catch any loading failures.
- Fetched results are cached by URL automatically.
To manage the cache, use the cacheKey prop:
- Use a unique
cacheKey to bust the cache when content at a stable URL changes. - Use the same
cacheKey across different components to deduplicate fetches for the same resource.
If the suspense prop is omitted, the components use their default behavior of asynchronous loading via onLoad and onError callbacks.
import { Suspense } from "react";
import { Viewer, GeoJsonDataSource } from "resium";
const App = () => (
<Viewer>
<Suspense fallback={<Loading />}>
<GeoJsonDataSource data="/path/to/data.geojson" suspense />
</Suspense>
</Viewer>
);
// Example with cacheKey to bust cache or dedupe
<GeoJsonDataSource data={url} suspense cacheKey="data-v2" />