Active value
Selected filters count
Toggle active function
Toggle product filter function
import { useFacet } from '@nosto/preact'
export default () => {
const { active, selectedFiltersCount, toggleActive, toggleProductFilter } = useFacet(facet)
return (
<li class={`ns-sidebar-dropdown ${active ? "ns-active" : ""}`}>
<a
href="javascript:void(0)"
onClick={toggleActive}
>
<span>{facet.name}</span>
{selectedFiltersCount > 0 && (
<span>{selectedFiltersCount}</span>
)}
</a>
<div>
<ul>
{facet.data?.map(value => (
<li key={value.value}>
<label>
{value.value}
<input
type="checkbox"
checked={value.selected}
onChange={e => {
e.preventDefault()
toggleProductFilter(
facet.field,
value.value,
!value.selected
)
}}
/>
</label>
<span>{value.count}</span>
</li>
))}
</ul>
</div>
</li>
);
}
Preact hook that import facet state to the component.