static Component()

in src/lib/components/molecules/canvas-map/lib/layers/TextLayer.js [16:82]


  static Component({
    features: featureCollection,
    style,
    minZoom,
    opacity,
    declutter,
    declutterBoundingBoxPadding,
    drawCollisionBoxes,
    onClick,
    onHover,
    restyleOnHover,
  }) {
    const { registerLayer, unregisterLayer } = useContext(MapContext)

    // We recreate layer whenever these properties change, which cannot be changed on the fly
    // and require recreation
    const layer = useMemo(
      () => {
        const features =
          featureCollection instanceof FeatureCollection
            ? featureCollection.features
            : /** @type {import("../Feature").Feature[]} */ (featureCollection)

        return TextLayer.with(features, {
          style,
          minZoom,
          opacity,
          declutter,
          declutterBoundingBoxPadding,
          drawCollisionBoxes,
          onClick,
          onHover,
          restyleOnHover,
        })
      },
      // eslint-disable-next-line react-hooks/exhaustive-deps
      [
        featureCollection,
        minZoom,
        opacity,
        declutter,
        declutterBoundingBoxPadding,
        drawCollisionBoxes,
        onClick,
        onHover,
        restyleOnHover,
      ],
    )

    useEffect(() => {
      registerLayer(layer, this)

      return () => {
        unregisterLayer(layer)
      }
      // eslint-disable-next-line react-hooks/exhaustive-deps
    }, [layer])

    useEffect(() => {
      // If the style prop changes, just update the layer, style can be changed without creating a
      // new layer
      layer.style = style
      // eslint-disable-next-line react-hooks/exhaustive-deps
    }, [style])

    return null
  }