Function useFacets

  • Preact hook that import facets to the component.

    Returns { facets: SearchFacet[]; loading: boolean }

    • facets: SearchFacet[]

      Array of facets

    • loading: boolean

      Loading state

    import { useFacets } from '@nosto/preact'
    import { defaultConfig } from "../config"

    export default () => {
    const { loading, facets } = useFacets()

    return (
    <div style={loading ? "opacity: 0.3;" : ""}>
    <div>
    <ul>
    {facets.map(facet => {
    switch (facet.type) {
    case "terms":
    return <Facet facet={facet} />
    case "stats":
    return <RangeFacet facet={facet} />
    default:
    return null
    }
    })}
    </ul>
    </div>
    </div>
    )
    }