For the complete documentation index, see llms.txt. This page is also available as Markdown.

Integrating with React

To work with Felt embeds in React, we have a starter template that you can use as a starting point.

This is available on GitHub in the felt/js-sdk-starter-react repository.

In that repo, you will find a feltUtils.ts file that demonstrates some ways to make using the Felt SDK in React easier. The SDK itself is framework-agnostic and ships no React bindings — the hooks below are small wrappers you copy into your own project.

Embedding with useFeltEmbed

function MyComponent() {
  // 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 map
  const { felt, mapRef } = useFeltEmbed("FELT_MAP_ID", {
    uiControls: {
      cooperativeGestures: false,
      fullScreenButton: false,
      showLegend: false,
    },
  });

  return (
    <div>
      {/* the map container — remember to give it a height in your CSS */}
      <div ref={mapRef} />

      {/* a component that uses the Felt controller */}
      <MyFeltApp felt={felt} />
    </div>
  );
}
useFeltEmbed implementation

A few things worth knowing about this hook:

  • The hasLoadedRef guard exists because React's Strict Mode runs effects twice in development — without it you would embed two iframes.

  • The hook embeds once for the component's lifetime: changing mapId after mount won't re-embed. If you need to switch maps, remount the component (for example with a key={mapId} prop).

Getting live data

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 felt.getLayers():

Last updated

Was this helpful?