Skip to main content
This is the React InstantSearch v7 documentation. If you’re upgrading from v6, see the upgrade guide. If you were using React InstantSearch Hooks, this v7 documentation applies—just check for necessary changes. To continue using v6, you can find the archived documentation.
Signature

Import

JavaScript

See this widget in action

Preview this widget and its behavior.

About this widget

<ToggleRefinement> is a widget that provides an on/off filter based on an attribute value. For example, you can use this widget to only display products that apply for free shipping, or recipes that are gluten-free.
You can also create your own UI with useToggleRefinement.

Requirements

Make sure to declare the provided attribute as an attribute for faceting.

Examples

JavaScript

Props

string
required
The name of the attribute in the .To avoid unexpected behavior, you can’t use the same attribute prop in a different type of widget.
JavaScript
string
The label to display for the checkbox.
JavaScript
boolean | string | number
The value of the refinement to apply on the attribute when checked.
boolean | string | number
The value of the refinement to apply on the attribute when unchecked.
Partial<ToggleRefinementClassNames>
The CSS classes you can override and pass to the widget’s elements. It’s useful to style widgets with class-based CSS frameworks like Bootstrap or Tailwind CSS.
  • root. The root element of the widget.
  • label. The label element.
  • checkbox. The checkbox element.
  • labelText. The text element of the label.
JavaScript
React.ComponentProps<'div'>
Any <div> prop to forward to the root element of the widget.
JavaScript

Hook

React InstantSearch let you create your own UI for the <ToggleRefinement> widget with useToggleRefinement. Hooks provide APIs to access the widget state and interact with InstantSearch. The useToggleRefinement Hook accepts parameters and returns APIs. It must be used inside the <InstantSearch> component.

Usage

First, create your React component:
JavaScript
Then, render the widget:
JavaScript

Parameters

Hooks accept parameters. You can either pass them manually or forward props from a custom component.
When passing functions to Hooks, ensure stable references to prevent unnecessary re-renders. Use useCallback() for memoization. Arrays and objects are automatically memoized.
string
required
The name of the attribute in the records.To avoid unexpected behavior, you can’t use the same attribute prop in a different type of widget.
JavaScript
boolean | string | number
The value of the refinement to apply on the attribute when checked.
boolean | string | number
The value of the refinement to apply on the attribute when unchecked.

APIs

Hooks return APIs, such as state and functions. You can use them to build your UI and interact with React InstantSearch.
ToggleRefinementValue
The current refinement.
TypeScript
boolean
Whether the search state can be refined.
JavaScript
({ isRefined: boolean }) => void
Updates to the next state by applying the toggle refinement.
JavaScript
(eventType: string, facetValue: string, eventName?: string) => void
A function to send click events. The click event is automatically sent when calling refine. To learn more, see the insights middleware.
JavaScript
() => string
Generates a URL for the next state.
JavaScript

Example

Last modified on July 22, 2026