No Preview

Sorry, but you either have no stories or none are selected somehow.

If the problem persists, check the browser console, or the terminal you've run Storybook from.

useSearchResultsSelectedFacets

The useSearchResultsSelectedFacets is a helper hook used in complement of useSearchResults who returns a list of facets selected in a Search Result Widget. It uses the value selectedFacets provided in useSearchResults hook to extend the list of facets selected with more information needed to render in a component.

Return Value

[ { id: string, name: string, values: [ { id: string, text: string } ] } ]

Importing

import { useSearchResultsSelectedFacets } from '@sitecore-search/react';

Usage

The following example shows how to use the useSearchResultsSelectedFacets within a React component. Remember that this hook is a complement from useSearchResults, so the component must be associated to that type of widget.

import { useSearchResultsSelectedFacets, useSearchResults } from '@sitecore-search/react'; const MySearchResultsFacets = () => { const { actions: onFilterClick } = useSearchResults(); const selectedFacets = useSearchResultsSelectedFacets(); return ( <> <ul> {selectedFacetsFromApi.map((selectedFacet) => selectedFacet.values.map((v) => ( <li> <span>{selectedFacet.name}:{v.text}</span> <button onClick={() => onFilterClick({ facetId: selectedFacet.id, facetValueId: v.id, checked: false })} > X </button> </li> )), )} </ul> </>); }