In that repo, you will find a feltUtils.ts file that demonstrates some ways to make using the Felt SDK in React easier.
Embedding with useFeltEmbed
functionMyComponent() {// get the felt controller (or null if it's not loaded yet) and a ref to the map container// into which we can embed the mapconst { felt,mapRef } =useFeltEmbed("wPV9BqMuYQxmUraVWy9C89BNA", { uiControls: { cooperativeGestures:false, fullScreenButton:false, showLegend:false, }, });return ( <div> {/* the map container */} <divref={mapRef} /> {/* a component that uses the Felt controller */} <MyFeltAppfelt={felt} /> </div> );}
A common use case for building apps on Felt is to be notified when entities are updated. The main example of this is when you want to change the visibility of say a layer, and have your own UI reflect that change.
Rather than keeping track of the visibility of entities yourself, you can use the Felt SDK to listen for changes to the visibility of entities.
Here is an example of how you might do this for layers assuming you already have a reference to a Layer object, e.g. from calling map.getLayers():
exportfunctionuseLiveLayer(felt:FeltController, initialLayer:Layer) {// start with the layer we were givenconst [currentLayer,setLayer] =React.useState<Layer|null>(initialLayer);// listen for changes to the layer and update our state accordinglyReact.useEffect(() => {returnfelt.onLayerChange({ options: { id:initialLayer.id },handler: ({ layer }) =>setLayer(layer), }); }, [initialLayer.id]);// return the live layerreturn currentLayer;}