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

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
);

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.

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. Uses a different constructor signature — no sourceId or map required.

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' },
});

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<IdentifyResult>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<IdentifyImageResult>Run identify at a point
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<QueryResult>Run a single-page query
queryAll(additionalOptions?) => Promise<QueryResult>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<FindResult>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>