Skip to content

GiraffeState

Iframes can listen to data from the parent Giraffe window using giraffeState.

Example usage

ts
import { giraffeState } from '@gi-nx/iframe-sdk';

giraffeState.addListener(['mapContent'], (key: string) => {
  console.log('mapContent has changed', giraffeState.get('mapContent'));
});

For React apps, use the useGiraffeState hook:

ts
function useGiraffeState<K extends GiraffeStateEventKey>(key: K): GiraffeStateGet[K]
ts
import { useGiraffeState } from '@gi-nx/iframe-sdk-react';

export const MyComponent = () => {
  const stackedSections = useGiraffeState('stackedSections');
  return <div>...</div>;
};

The returned snapshot is read-only. Don't mutate it. Copy before editing: const editable = structuredClone(snap) (deep) or const editable = { ...snap } (shallow).

State Types

The available keys and their types:

KeyType
selectedGiraffeStateSelected
mapViewMapView
mapContentMapContent
mapSelectCoordGiraffeStateMapSelectCoord
projectsGiraffeStateProjects
bakedSectionsGiraffeStateBakedSections
projectLayersGiraffeStateProjectLayers
rawSectionsGiraffeStateRawSections
flowsGiraffeStateFlows
blocksGiraffeStateBlocks
projectGiraffeStateProject
projectOriginGiraffeStateProjectOrigin
projectAppsByAppIDGiraffeStateProjectAppsByAppID
layerTreeGiraffeStateLayerTree
selectedProjectAppGiraffeStateSelectedProjectApp
mapHoverCoordsGiraffeStateMapHoverCoords
closingSignalGiraffeStateClosingSignal
uiLayoutGiraffeStateUiLayout
contextMenuClickGiraffeStateContextMenuClick
viewsGiraffeStateViews
mapboxEventGiraffeStateMapboxEvent
workspaceGiraffeStateWorkspace
visibleScenariosGiraffeStateVisibleScenarios