Property to tell if user has used facets to filter results

Hi All!
I am looking for a way to check if an user filtered results using the facets.
Is there a property to check this? I looked at search.helper.lastResults.exhaustive.facetsCount but this is not what i need.

I am using native javascript / instantsearch 4.

thanks so much!

@mauritsvdh welcome to the community!

One way I’ve done this in the past is to access this information via the renderState which is an attribute inside the search object:

for (const [name, value] of Object.entries(search.renderState[search.indexName].refinementList)) {
  const facetActiveRefinements = value.items.filter(value => value.isRefined)
  console.log('Facet', name, 'has active refinements:', facetActiveRefinements)

Which will output:

Facet room_type has active refinements: [{ ... isRefined: true, value: 'Private room', ...}]

More information and examples can be found here in our documentation. Happy to help further, let us know! Thanks!

Thanks so much Michael! That works perfect!

1 Like