ClearFilters lets users clear all refinements that are currently active within the given FilterState.To add ClearFilters to your search experience, use these components:
FilterClearViewModel. The logic for clearing refinements in the FilterState.
FilterState. The current state of the filters.
FilterClearView. The view that renders the clear filter UI.
InstantSearch provides the FilterClear as a state model,
which is an implementation of the FilterClearView interface.
You need to connect FilterClear to the FilterClearConnector or FilterClearViewModel like any other FilterClearView implementation.
Kotlin
class MyActivity : AppCompatActivity() { val searcher = HitsSearcher( applicationID = "YourApplicationID", apiKey = "YourSearchOnlyAPIKey", indexName = "YourIndexName" ) val color = "color" val category = "category" val groupColor = groupOr(color) val groupCategory = groupOr(category) val filters = filters { group(groupColor) { facet(color, "red") facet(color, "green") } group(groupCategory) { facet(category, "shoe") } } val filterState = FilterState() val filterClear = FilterClear() val clearAll = FilterClearConnector(filterState = filterState) val connections = ConnectionHandler(clearAll) init { connections += searcher.connectFilterState(filterState) connections += clearAll.connectView(filterClear) } override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContent { MyClearButton(clearAll) // your own composable to trigger filter clear } searcher.searchAsync() } override fun onDestroy() { super.onDestroy() searcher.cancel() connections.disconnect() }}