Skip to main content

React Hooks

React hooks for managing Esri service lifecycle and running spatial tasks. All hooks handle loading state, error handling, and cleanup automatically.

Service Hooks​

These hooks create and manage Esri service instances tied to a map. They all return { service, loading, error, reload }.

useEsriService​

Base hook for managing any Esri service lifecycle. Used internally by all other service hooks.

ParameterTypeDescription
createService(map: Map) => TFactory function to create a service instance
mapMap | nullMapLibre GL or Mapbox GL map instance
depsReadonlyArray<unknown>Optional. Values that rebuild the service (and its source) when they change — the hook otherwise only rebuilds when map changes

Returns: UseEsriServiceResult<T>

PropertyTypeDescription
serviceT | nullThe service instance
loadingbooleanWhether the service is initializing
errorError | nullAny error during creation
reload() => voidRecreate the service
const { service, loading, error } = useEsriService(
(map) => new DynamicMapService('my-source', map, { url: serviceUrl }),
map,
[serviceUrl] // rebuild when the url changes
);

useDynamicMapService​

Hook for DynamicMapService. Automatically updates layers and layerDefs when options change without recreating the service.

ParameterTypeDescription
sourceIdstringSource ID for the map
mapMap | nullMap instance
optionsEsriServiceOptionsService options including url, layers, layerDefs, etc.
sourceOptionsRecord<string, unknown>Optional raster source options

Returns: UseEsriServiceResult<DynamicMapService>

const { service, loading } = useDynamicMapService({
sourceId: 'demographics',
map,
options: { url: 'https://sampleserver6.arcgisonline.com/arcgis/rest/services/Census/MapServer' },
});

useTiledMapService​

Hook for TiledMapService.

ParameterTypeDescription
sourceIdstringSource ID for the map
mapMap | nullMap instance
optionsEsriServiceOptionsService options including url
sourceOptionsRecord<string, unknown>Optional raster source options

Returns: UseEsriServiceResult<TiledMapService>

const { service } = useTiledMapService({
sourceId: 'basemap',
map,
options: { url: 'https://services.arcgisonline.com/arcgis/rest/services/World_Topo_Map/MapServer' },
});

useImageService​

Hook for ImageService. A changed url or format rebuilds the service (and its source); renderingRule / mosaicRule changes are applied in place. Pass a memoized options object.

ParameterTypeDescription
sourceIdstringSource ID for the map
mapMap | nullMap instance
optionsImageServiceOptionsService options including url, renderingRule, mosaicRule
sourceOptionsRecord<string, unknown>Optional raster source options

Returns: UseEsriServiceResult<ImageService>

const { service } = useImageService({
sourceId: 'elevation',
map,
options: { url: 'https://sampleserver6.arcgisonline.com/arcgis/rest/services/NLCDLandCover/ImageServer' },
});

useFeatureService​

Hook for FeatureService.

ParameterTypeDescription
sourceIdstringSource ID for the map
mapMap | nullMap instance
optionsFeatureServiceOptionsService options including url, where, outFields
sourceOptionsRecord<string, unknown>Optional GeoJSON source options

Returns: UseEsriServiceResult<FeatureService>

const { service } = useFeatureService({
sourceId: 'parcels',
map,
options: {
url: 'https://sampleserver6.arcgisonline.com/arcgis/rest/services/Census/MapServer/3',
where: "STATE_NAME='California'",
},
});

useVectorTileService​

Hook for VectorTileService.

ParameterTypeDescription
sourceIdstringSource ID for the map
mapMap | nullMap instance
optionsVectorTileServiceOptionsService options including url
sourceOptionsRecord<string, unknown>Optional source options

Returns: UseEsriServiceResult<VectorTileService>

const { service } = useVectorTileService({
sourceId: 'vtiles',
map,
options: { url: 'https://basemaps.arcgis.com/arcgis/rest/services/World_Basemap_v2/VectorTileServer' },
});

useVectorBasemapStyle​

Hook for VectorBasemapStyle. Takes only { options } — no sourceId or map, because a basemap style is applied with map.setStyle(service.styleUrl) rather than added as a source. Returns service: null until a token or apiKey is supplied.

ParameterTypeDefaultDescription
options.basemapEnumstring'arcgis/streets'Basemap style enum
options.tokenstringAuthentication token
options.apiKeystringAPI key
options.languagestringLabel language
options.worldviewstringWorldview

Returns: UseEsriServiceResult<VectorBasemapStyle>

const { service } = useVectorBasemapStyle({
options: { basemapEnum: 'arcgis/navigation', token: 'YOUR_TOKEN' },
});

useEffect(() => {
if (map && service) map.setStyle(service.styleUrl);
}, [map, service]);

usePortalItem​

Deprecated

When you know the service type, pass the item id straight to the matching service hook as its url — e.g. useDynamicMapService({ options: { url: itemId } }). Use usePortalItem only when the type has to be auto-detected from the item.

Resolves an ArcGIS portal item id to the matching esri-gl service via serviceFromPortalItem and adds its source to the map. Re-resolves when itemId or map change, cleaning up the previous service.

ParameterTypeDescription
sourceIdstringSource ID for the map
mapMap | nullMap instance
itemIdstringArcGIS portal item id to resolve
optionsPortalItemServiceOptionsAuth (token/apiKey/authentication), portal, layerId, and per-kind source options

Returns:

PropertyTypeDescription
servicePortalResolvedService | nullThe resolved service (source already on the map)
kindPortalServiceKind | null'dynamic', 'tiled', 'image', 'vector-tile', or 'feature'
urlstring | nullThe service URL the item resolved to
titlestring | nullThe portal item title
loadingbooleanResolution in progress
errorError | nullResolution error, if any
reload() => voidRe-resolve the item
const { service, kind, title, loading, error } = usePortalItem({
sourceId: 'portal-src',
map,
itemId: 'a1b2c3d4e5f6',
options: { token: 'YOUR_TOKEN' },
});

See the Portal Items guide for item-type mapping and Web Map resolution.

Task Hooks​

These hooks wrap spatial tasks with loading/error state management.

useIdentifyFeatures​

Hook for running IdentifyFeatures tasks.

ParameterTypeDescription
urlstringMapService URL
tolerancenumberPixel tolerance for identify
returnGeometrybooleanInclude geometry in results

Returns:

PropertyTypeDescription
identify(point, additionalOptions?) => Promise<GeoJSON.FeatureCollection>Run identify at a point
loadingbooleanWhether a request is in progress
errorError | nullAny error from the last request

The identify function accepts a { lng, lat } point and optional additional options including { map } to scope results to the current map extent.

const { identify, loading, error } = useIdentifyFeatures({
url: 'https://sampleserver6.arcgisonline.com/arcgis/rest/services/Census/MapServer',
tolerance: 3,
returnGeometry: true,
});

const results = await identify({ lng: -118.24, lat: 34.05 }, { map });

useIdentifyImage​

Hook for running IdentifyImage tasks on image services.

ParameterTypeDescription
urlstringImageService URL
tokenstringOptional authentication token
returnGeometrybooleanInclude geometry in results

Returns:

PropertyTypeDescription
identifyImage(point, additionalOptions?) => Promise<IdentifyImageResponse>Run identify at a point (the { results, location } response)
loadingbooleanWhether a request is in progress
errorError | nullAny error from the last request
const { identifyImage, loading } = useIdentifyImage({
url: 'https://sampleserver6.arcgisonline.com/arcgis/rest/services/NLCDLandCover/ImageServer',
});

const result = await identifyImage({ lng: -118.24, lat: 34.05 });

useQuery​

Hook for running Query tasks with pagination support.

ParameterTypeDescription
urlstringFeature layer URL
wherestringSQL WHERE clause
outFieldsstring | string[]Fields to return
returnGeometrybooleanInclude geometry in results

Returns:

PropertyTypeDescription
query(additionalOptions?) => Promise<GeoJSON.FeatureCollection>Run a single-page query
queryAll(additionalOptions?) => Promise<GeoJSON.FeatureCollection>Run a paginated query (supports maxPages)
loadingbooleanWhether a request is in progress
errorError | nullAny error from the last request
const { query, queryAll, loading } = useQuery({
url: 'https://sampleserver6.arcgisonline.com/arcgis/rest/services/Census/MapServer/3',
where: "STATE_NAME='California'",
outFields: ['STATE_NAME', 'POP2000'],
returnGeometry: false,
});

const page = await query();
const all = await queryAll({ maxPages: 5 });

useFind​

Hook for running Find tasks to search across multiple layers.

ParameterTypeDescription
urlstringMapService URL
searchTextstringText to search for
layersstring | number[]Layer IDs to search
searchFieldsstring | string[]Fields to search in

Returns:

PropertyTypeDescription
find(additionalOptions?) => Promise<GeoJSON.FeatureCollection>Run the find operation
loadingbooleanWhether a request is in progress
errorError | nullAny error from the last request
const { find, loading } = useFind({
url: 'https://sampleserver6.arcgisonline.com/arcgis/rest/services/Census/MapServer',
searchText: 'California',
layers: [2, 3],
searchFields: ['STATE_NAME'],
});

const results = await find();

useFeatureEditing​

Hook for editing features on a FeatureService.

ParameterTypeDescription
serviceFeatureService | nullThe FeatureService instance to edit

Returns:

PropertyTypeDescription
addFeatures(features, options?) => Promise<EditResult[]>Add new features
updateFeatures(features, options?) => Promise<EditResult[]>Update existing features
deleteFeatures(params) => Promise<EditResult[]>Delete features by IDs or WHERE clause
applyEdits(edits, options?) => Promise<ApplyEditsResult>Batch add/update/delete in one call
loadingbooleanWhether an edit is in progress
errorError | nullAny error from the last edit
lastResultEditResult[] | ApplyEditsResult | nullResult of the last edit operation
const { service } = useFeatureService({ sourceId: 'parcels', map, options: { url: featureUrl } });
const { addFeatures, deleteFeatures, loading } = useFeatureEditing(service);

await addFeatures([{ type: 'Feature', geometry: { type: 'Point', coordinates: [-118, 34] }, properties: { name: 'New' } }]);
await deleteFeatures({ objectIds: [42] });

Context​

EsriServiceProvider​

Context provider for sharing a map instance with child Esri components.

import { EsriServiceProvider } from 'esri-gl/react';

function App() {
const [map, setMap] = useState(null);
return (
<EsriServiceProvider map={map}>
<MapView onLoad={setMap} />
<LayerPanel />
</EsriServiceProvider>
);
}

useEsriMap​

Hook to access the map instance from EsriServiceProvider.

Returns: Map | null

const map = useEsriMap();

EsriLayer​

Generic layer component that adds a MapLibre GL layer to the map. Must be used within EsriServiceProvider.

PropTypeDescription
sourceIdstringSource to use for the layer
layerIdstringUnique layer ID
typestringLayer type: 'raster', 'fill', 'line', 'symbol', 'circle', etc.
paintRecord<string, unknown>Paint properties
layoutRecord<string, unknown>Layout properties
beforeIdstringInsert layer before this layer ID
<EsriServiceProvider map={map}>
<EsriLayer sourceId="parcels" layerId="parcels-fill" type="fill" paint={{ 'fill-color': '#0080ff', 'fill-opacity': 0.3 }} />
</EsriServiceProvider>