> ## Documentation Index
> Fetch the complete documentation index at: https://algolia.com/llms.txt
> Use this file to discover all available pages before exploring further.

# ClearRefinements

> Lets users reset all applied search refinements.

<div className="not-prose algolia-flavor-switcher">
  <div className="afs-dropdown">
    <div className="afs-trigger" role="button" tabIndex="0" aria-haspopup="listbox">
      <span className="afs-current">React</span>

      <svg className="afs-chevron lucide lucide-chevron-down" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true">
        <path d="m6 9 6 6 6-6" />
      </svg>
    </div>

    <ul className="afs-menu" role="listbox">
      <li role="option" aria-selected="false"><a className="afs-option" href="/doc/api-reference/widgets/clear-refinements/js"><span className="afs-option-name">JavaScript</span><span className="afs-option-lib">InstantSearch.js</span></a></li>
      <li role="option" aria-selected="true"><a className="afs-option is-current" href="/doc/api-reference/widgets/clear-refinements/react"><span className="afs-option-name">React</span><span className="afs-option-lib">React InstantSearch</span></a></li>
      <li role="option" aria-selected="false"><a className="afs-option" href="/doc/api-reference/widgets/clear-refinements/vue"><span className="afs-option-name">Vue</span><span className="afs-option-lib">Vue InstantSearch</span></a></li>
      <li role="option" aria-selected="false"><a className="afs-option" href="/doc/api-reference/widgets/clear-refinements/ios"><span className="afs-option-name">iOS</span><span className="afs-option-lib">InstantSearch iOS</span></a></li>
      <li role="option" aria-selected="false"><a className="afs-option" href="/doc/api-reference/widgets/clear-refinements/android"><span className="afs-option-name">Android</span><span className="afs-option-lib">InstantSearch Android</span></a></li>
      <li role="option" aria-selected="false"><a className="afs-option" href="/doc/api-reference/widgets/clear-refinements/flutter"><span className="afs-option-name">Flutter</span><span className="afs-option-lib">Algolia for Flutter</span></a></li>
    </ul>
  </div>
</div>

<Note>
  This is the **React InstantSearch v7** documentation.
  If you're upgrading from v6, see the [upgrade guide](/doc/guides/building-search-ui/upgrade-guides/react/#migrate-from-react-instantsearch-v6-to-react-instantsearch-v7).
  If you were using React InstantSearch Hooks,
  this v7 documentation applies—just check for [necessary changes](/doc/guides/building-search-ui/upgrade-guides/react/#migrate-from-react-instantsearch-hooks-to-react-instantsearch-v7).
  To continue using v6, you can find the [archived documentation](https://algolia.com/old-docs/deprecated/instantsearch/react/v6/api-reference/instantsearch/).
</Note>

```tsx Signature theme={"system"}
<ClearRefinements
  // Optional props
  includedAttributes={string[]}
  excludedAttributes={string[]}
  transformItems={function}
  classNames={object}
  translations={object}
  ...props={ComponentProps<'div'>}
/>
```

## Import

```jsx JavaScript icon=code theme={"system"}
import { ClearRefinements } from "react-instantsearch";
```

<Card title="See this widget in action" icon="monitor-play" href="https://instantsearchjs.netlify.app/stories/js/?path=/story/sorting-clearrefinements--default" horizontal>
  Preview this widget and its behavior.
</Card>

## 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.

<Tip>You can also create your own UI with [`useClearRefinements`](#hook).</Tip>

## Examples

```jsx JavaScript icon=code theme={"system"}
import React from "react";
import { liteClient as algoliasearch } from "algoliasearch/lite";
import { InstantSearch, ClearRefinements } from "react-instantsearch";

const searchClient = algoliasearch("YourApplicationID", "YourSearchOnlyAPIKey");

function App() {
  return (
    <InstantSearch indexName="instant_search" searchClient={searchClient}>
      <ClearRefinements />
    </InstantSearch>
  );
}
```

## Props

<ParamField body="includedAttributes" type="string[]" default="[]">
  The attributes to include in the refinements to clear (all by default).
  Can't be used with [`excludedAttributes`](/doc/api-reference/widgets/clear-refinements/react#param-excluded-attributes).
  In the example below, only the `categories` attribute is included in the refinements to clear.

  ```jsx JavaScript icon=code theme={"system"}
  <ClearRefinements includedAttributes={["categories"]} />;
  ```
</ParamField>

<ParamField body="excludedAttributes" type="string[]" default="['query']">
  The attributes to exclude from the refinements to clear.
  Can't be used with [`includedAttributes`](/doc/api-reference/widgets/clear-refinements/react#param-included-attributes).
  In the example below, the attribute `brand` is excluded from the refinements to clear.

  ```jsx JavaScript icon=code theme={"system"}
  <CurrentRefinements excludedAttributes={["brand"]} />;
  ```
</ParamField>

<ParamField body="transformItems" type="(items: object[], metadata: { results: SearchResults }) => object[]">
  A function that receives the list of items before they are displayed.
  It should return a new array with the same structure.
  Use this to transform, filter, or reorder the items.

  The function also has access to the full `results` data,
  including all standard [response parameters](/doc/guides/building-search-ui/going-further/backend-search/in-depth/understanding-the-api-response/)
  and [parameters from the helper](https://community.algolia.com/algoliasearch-helper-js/reference.html#query-parameters),
  such as `disjunctiveFacetsRefinements`.

  <CodeGroup>
    ```jsx JavaScript theme={"system"}
    const transformItems = (items) => {
      return items.filter((item) => item.attribute !== "brand");
    };

    function Search() {
      return (
        <ClearRefinements
          // ...
          transformItems={transformItems}
        />
      );
    }
    ```

    ```tsx TypeScript theme={"system"}
    import type { ClearRefinementsProps } from "react-instantsearch";

    const transformItems: ClearRefinementsProps["transformItems"] = (items) => {
      return items.filter((item) => item.attribute !== "brand");
    };

    function Search() {
      return (
        <ClearRefinements
          // ...
          transformItems={transformItems}
        />
      );
    }
    ```
  </CodeGroup>
</ParamField>

<ParamField body="classNames" type="Partial<ClearRefinementsClassNames>">
  The [CSS classes you can override](/doc/guides/building-search-ui/widgets/customize-an-existing-widget/react#style-your-widgets) and pass to the widget's elements.
  It's useful to style widgets with class-based CSS frameworks like [Bootstrap](https://getbootstrap.com) or [Tailwind CSS](https://tailwindcss.com).

  * `root`. The root element of the widget.
  * `button`. The button element.
  * `disabledButton`. The button element when there are no refinements to clear.

  ```jsx JavaScript icon=code theme={"system"}
  <ClearRefinements
    classNames={{
      root: "MyCustomClearRefinements",
      button:
        "MyCustomClearRefinementsButton MyCustomClearRefinementsButton--subclass",
    }}
  />;
  ```
</ParamField>

<ParamField body="translations" type="Partial<ClearRefinementsTranslations>">
  A dictionary of translations to customize the UI text and support internationalization.

  * `resetButtonText`. The text for the reset button.

  ```jsx JavaScript icon=code theme={"system"}
  <ClearRefinements
    translations={{
      resetButtonText: "Clear all",
    }}
  />;
  ```
</ParamField>

<ParamField body="...props" type="React.ComponentProps<'div'>">
  Any `<div>` prop to forward to the root element of the widget.

  ```jsx JavaScript icon=code theme={"system"}
  <ClearRefinements
    className="MyCustomClearRefinements"
    title="My custom title"
  />;
  ```
</ParamField>

## Hook

React InstantSearch 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](#parameters) and returns [APIs](#hook).
It must be used inside the [`<InstantSearch>`](/doc/api-reference/widgets/instantsearch/react) component.

### Usage

First, create your React component:

```jsx JavaScript icon=code theme={"system"}
import { useClearRefinements } from "react-instantsearch";

function CustomClearRefinements(props) {
  const { refine, canRefine, createURL } = useClearRefinements(props);

  return <>{/*Your JSX*/}</>;
}
```

Then, render the widget:

```jsx JavaScript icon=code theme={"system"}
<CustomClearRefinements {...props} />
```

### Parameters

Hooks accept parameters. You can either pass them manually or forward props from a custom component.

<Note>
  When passing functions to Hooks, ensure stable references to prevent unnecessary re-renders.
  Use [`useCallback()`](https://reactjs.org/docs/hooks-reference.html#usecallback) for memoization.
  Arrays and objects are automatically memoized.
</Note>

<ParamField body="includedAttributes" type="string[]" default="[]">
  The attributes to include in the refinements to clear (all by default).
  Can't be used with [`excludedAttributes`](/doc/api-reference/widgets/clear-refinements/react#param-excluded-attributes).
  In the example below, only the `categories` attribute is included in the refinements to clear.

  ```jsx JavaScript icon=code theme={"system"}
  const clearRefinementsApi = useClearRefinements({
    includedAttributes: ["categories"],
  });
  ```
</ParamField>

<ParamField body="excludedAttributes" type="string[]" default="['query']">
  The attributes to exclude from the refinements to clear.
  Can't be used with [`includedAttributes`](/doc/api-reference/widgets/clear-refinements/react#param-included-attributes).
  In the example below, the attribute `brand` is excluded from the refinements to clear.

  ```jsx JavaScript icon=code theme={"system"}
  const clearRefinementsApi = useClearRefinements({
    excludedAttributes: ["brand"],
  });
  ```
</ParamField>

<ParamField body="transformItems" type="(items: string[], metadata: { results: SearchResults }) => string[]">
  A function that receives the list of items before they are displayed.
  It should return a new array with the same structure.
  Use this to transform, filter, or reorder the items.

  The function also has access to the full `results` data,
  including all standard [response parameters](/doc/guides/building-search-ui/going-further/backend-search/in-depth/understanding-the-api-response/)
  and [parameters from the helper](https://community.algolia.com/algoliasearch-helper-js/reference.html#query-parameters),
  such as `disjunctiveFacetsRefinements`.

  <CodeGroup>
    ```jsx JavaScript theme={"system"}
    const transformItems = (items) => {
      return items.filter((item) => item !== "brand");
    };

    function ClearRefinements() {
      const clearRefinementsApi = useClearRefinements({
        // ...
        transformItems,
      });

      return <>{/* Your JSX */}</>;
    }
    ```

    ```tsx TypeScript theme={"system"}
    import type { UseClearRefinementsProps } from "react-instantsearch";

    const transformItems: UseClearRefinementsProps["transformItems"] = (items) => {
      return items.filter((item) => item !== "brand");
    };

    function ClearRefinements() {
      const clearRefinementsApi = useClearRefinements({
        // ...
        transformItems,
      });

      return <>{/* Your JSX */}</>;
    }
    ```
  </CodeGroup>
</ParamField>

### APIs

Hooks return APIs, such as state and functions.
You can use them to build your UI and interact with React InstantSearch.

<ResponseField name="refine" type="() => void">
  Clears all the currently refined values and triggers a new search.
</ResponseField>

<ResponseField name="canRefine" type="boolean">
  Indicates if search state can be refined.
</ResponseField>

<ResponseField name="createURL" type="() => string">
  Generates a URL of the next state.
</ResponseField>

### Example

<CodeGroup>
  ```jsx JavaScript theme={"system"}
  import React from "react";
  import { useClearRefinements } from "react-instantsearch";

  function CustomClearRefinements(props) {
    const { canRefine, refine } = useClearRefinements(props);

    return (
      <button disabled={!canRefine} onClick={refine}>
        Clear refinements
      </button>
    );
  }
  ```

  ```tsx TypeScript theme={"system"}
  import React from "react";
  import {
    useClearRefinements,
    UseClearRefinementsProps,
  } from "react-instantsearch";

  function CustomClearRefinements(props: UseClearRefinementsProps) {
    const { canRefine, refine } = useClearRefinements(props);

    return (
      <button disabled={!canRefine} onClick={refine}>
        Clear refinements
      </button>
    );
  }
  ```
</CodeGroup>
