geoview-core
    Preparing search index...

    Function useStableSelector

    • A React hook that wraps a Zustand store selector and preserves the previous reference if the selected value is equal to the previous one, preventing unnecessary re-renders. This is useful when the store returns a new object or array on every update, but you want to avoid infinite render loops or excessive component updates.

      Type Parameters

      • T

        The type of the selected state slice.

      Parameters

      • store: GeoviewStoreType

        The Zustand store instance to subscribe to.

      • selector: (state: IGeoviewState) => T

        A function that selects a piece of state from the store.

      • OptionalisEqual: EqualityFn<T> = shallowObjectEqual

        A function that compares the previous and next selector results. Should return true if they are equal and reference can be reused.

      Returns T

      The selected state slice. Returns the previous reference if isEqual(prev, next) is true.

      const queryableLayers = useStableSelector(
      store,
      (state) => state.layers.reduce((acc, layer) => ({ ...acc, [layer.id]: layer.queryable }), {}),
      shallowObjectEqual
      );