useFilters

Purpose

The useFilters hook returns the active Filters being used based on the search mode, active curations and other factors, internally it is used by the Filters component.

Usage

import React from "react";
import { useFilters, Filter } from "@usereactify/search";

export const ExampleHookUseFilters: React.FC = () => {
  const filtersHook = useFilters();

  return (
    <div>
      <h1>{"Filters"}</h1>
      {filtersHook.filters?.map((filter) => (
        <div>
          <h3>{filter.name}</h3>
          <Filter
            key={filter.id}
            filter={filter}
          />
        </div>
      ))}
    </div>
  );
};

Signature

(): {
  /** The currently selected filter stack based on mode, curation and more */
  filterStack?: ConfigFilter;
  /** All of the available filters within the filter stack */
  filters?: Array<ConfigFilterOption>;
}

Last updated