<ClearRefinements>
<ClearRefinements // Optional props includedAttributes={string[]} excludedAttributes={string[]} transformItems={ClearRefinementsProps['transformItems']} classNames={Partial<ClearRefinementsClassNames>} ...props={React.ComponentProps<'div'>} />
About this widget
<ClearRefinements>
is a widget that resets the active refinements of the search.
You can control which attributes are cleared with the props.
You can also create your own UI with
useClearRefinements()
.
Examples
1
2
3
4
5
6
7
8
9
10
11
12
13
import React from 'react';
import algoliasearch from 'algoliasearch/lite';
import { InstantSearch, ClearRefinements } from 'react-instantsearch-hooks-web';
const searchClient = algoliasearch('YourApplicationID', 'YourSearchOnlyAPIKey');
function App() {
return (
<InstantSearch indexName="instant_search" searchClient={searchClient}>
<ClearRefinements />
</InstantSearch>
);
}
Props
includedAttributes
|
type: string[]
default: []
The attributes to include in the refinements to clear (all by default). Can’t be used with |
||
Copy
|
|||
excludedAttributes
|
type: string[]
default: ["query"]
The attributes to exclude from the refinements to clear. Can’t be used with |
||
Copy
|
|||
transformItems
|
type: ClearRefinementsProps['transformItems']
Optional
Function which receives the items to clear, which is called before clearing them. Should return a new array with the same shape as the original array. Useful for filtering items. In addition, the full |
||
Copy
|
|||
classNames
|
type: Partial<ClearRefinementsClassNames>
Optional
CSS classes to pass to the widget’s elements. This is useful to style widgets with class-based CSS frameworks like Bootstrap or Tailwind CSS.
|
||
Copy
|
|||
...props
|
type: React.ComponentProps<'div'>
Optional
Any |
||
Copy
|
Hook
React InstantSearch Hooks let you create your own UI for the <ClearRefinements>
widget with useClearRefinements()
. Hooks provide APIs to access the widget state and interact with InstantSearch.
The useClearRefinements()
Hook accepts parameters and returns APIs.
Usage
First, create your React component:
import { useClearRefinements } from 'react-instantsearch-hooks-web';
function CustomClearRefinements(props) {
const { refine, canRefine, createURL } = useClearRefinements(props);
return <>{/* Your JSX */}</>;
}
Then, render the widget:
<CustomClearRefinements {...props} />
Parameters
Hooks accept parameters. You can pass them manually, or forward the props from your custom component.
When you provide a function to Hooks, make sure to pass a stable reference with useCallback()
to avoid rendering endlessly. Objects and arrays are memoized so you don’t have to stabilize them.
includedAttributes
|
type: string[]
default: []
The attributes to include in the refinements to clear (all by default). Can’t be used with |
||
Copy
|
|||
excludedAttributes
|
type: string[]
default: ["query"]
The attributes to exclude from the refinements to clear. Can’t be used with |
||
Copy
|
|||
transformItems
|
type: UseClearRefinementsProps['transformItems']
Optional
Function which receives the items to clear, which is called before clearing them. Should return a new array with the same shape as the original array. Useful for filtering items. In addition, the full |
||
Copy
|
APIs
Hooks return APIs, such as state and functions. You can use them to build your UI and interact with React InstantSearch.
refine
|
type: () => void
Clears all the currently refined values and triggers a new search. |
canRefine
|
type: boolean
Indicates if search state can be refined. |
createURL
|
type: () => string
Generates a URL of the next state. |
Example
1
2
3
4
5
6
7
8
import React from 'react';
import { useClearRefinements } from 'react-instantsearch-hooks-web';
function CustomClearRefinements(props) {
const { canRefine, refine } = useClearRefinements(props);
return <>{/* Your JSX */}</>;
}