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
About this widget
<RefinementList>
is a widget that lets users filter the dataset using multi-select facets.
A refinement list only displays the most relevant facet values for the current search context.
The sortBy
option only affects how the facets are ordered, not which facets are returned.
This widget includes a “search for facet values” feature,
enabling users to search through the values of a specific facet attribute.
This makes it easy to find uncommon facet values.
The
attribute
provided to the widget must be in attributes for faceting,
either on the dashboard or using the attributesForFaceting
parameter with the API.If you are using the searchable
prop, you also need to make the attribute searchable using the dashboard or using the searchable
modifier of attributesForFaceting
with the API.Disappearing facet values
With many facet values, the available options can change depending on the user’s query. The refinement widget displays the most common facet values for a given query. A user’s chosen value can vanish if they alter the query. This occurs because only the most common facet values are displayed when there are many options. A previously selected value might not appear if it’s uncommon for the new query. To also show less common values, adjust the maximum number of values with theconfigure
widget.
It doesn’t change how many items are shown: the limits you set with limit
and showMoreLimit
still apply.
How to implement a “Show more” feature
A customuseRefinementList
widget displays up to showMoreLimit
refinement items
.
You can sort the items as desired before they’re trimmed.
However, you’ll need to slice to the appropriate limit
and keep track of isShowingMore
in the local state:
JavaScript
You can also create your own UI with
useRefinementList
.Examples
JavaScript
Props
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
How the facets are combined.
'or'
: Returns results matching any of the selected values.'and'
: Returns results matching all selected values.
JavaScript
How many facet values to retrieve.When you set
showMore
and showMoreLimit
,
this is the number of facet values to display before clicking the Show more button.JavaScript
Whether to display a button that expands the number of items.
JavaScript
The maximum number of items to display if the widget is showing more items.
JavaScript
Whether to add a search input to let users search for more facet values.You need to make the
attribute
searchable using the dashboard) or using the searchable
modifier of attributesForFaceting
with the API.In some situations, refined facet values might not be present in the data
returned by Algolia.
JavaScript
The value of the search input’s placeholder.
JavaScript
How to sort refinements. Must be one or more of the following strings:
"count"
(same as"count:desc"
)"count:asc"
"count:desc"
"name"
(same as"name:asc"
)"name:asc"
"name:desc"
"isRefined"
(same as"isRefined:asc"
)"isRefined:asc"
"isRefined:desc"
compareFunction
.When you don’t set this parameter,
and you’ve set facetOrdering
for this facet in renderingContent
,
facets are sorted using facetOrdering
and use the default order as a fallback.In some situations, refined facet values might not be present in the data
returned by Algolia.
Escapes the content of the facet values returned by Algolia.When using this parameter,
the highlighting tags are always
mark
.JavaScript
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
and parameters from the helper,
such as disjunctiveFacetsRefinements
.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.noRefinementRoot
. The root element when there are no refinements.searchBox
. The search box element.noResults
. The root element of the widget when there are no results.list
. The list element.item
. Each item element.selectedItem
. Each selected item element.label
. The label of each item.checkbox
. The checkbox of each item.labelText
. The text element of each label.count
. The count of each item.showMore
. The “Show more” button.disabledShowMore
. The disabled “Show more” button.
JavaScript
A dictionary of translations to customize the UI text and support internationalization.
submitButtonTitle
. The submit button title of the search box.resetButtonTitle
. The reset button title search box.noResultsText
. The text to display when searching for facets returns no results.showMoreButtonText
. The text for the “Show more” button.
JavaScript
Any
<div>
prop to forward to the root element of the widget.JavaScript
Hook
React InstantSearch let you create your own UI for the<RefinementList>
widget with useRefinementList
.
Hooks provide APIs to access the widget state and interact with InstantSearch.
The useRefinementList
Hook accepts parameters and returns APIs.
It must be used inside the <InstantSearch>
component.
Usage
First, create your React component:JavaScript
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.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
How the filters are combined.
'or'
: Returns results matching any of the selected values.'and'
: Returns results matching all selected values.
JavaScript
How many facet values to retrieve.When you set
showMore
and showMoreLimit
,
this is the number of facet values to display before clicking the Show more button.JavaScript
Whether to display a button that expands the number of items.
JavaScript
The maximum number of items to display if the widget is showing more items.
JavaScript
How to sort refinements. Must be one or more of the following strings:
"count"
(same as"count:desc"
)"count:asc"
"count:desc"
"name"
(same as"name:asc"
)"name:asc"
"name:desc"
"isRefined"
(same as"isRefined:asc"
)"isRefined:asc"
"isRefined:desc"
compareFunction
.When you don’t set this parameter,
and you’ve set facetOrdering
for this facet in renderingContent
,
facets are sorted using facetOrdering
and use the default order as a fallback.In some situations, refined facet values might not be present in the data
returned by Algolia.
Escapes the content of the facet values returned by Algolia.When using this parameter, the highlighting tags are always
mark
.JavaScript
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
and parameters from the helper,
such as disjunctiveFacetsRefinements
.APIs
Hooks return APIs, such as state and functions. You can use them to build your UI and interact with React InstantSearch.The list of filtering values returned by Algolia.
Type definition
Whether the results are exhaustive.
Creates the next state URL of a selected refinement.
Applies the selected refinement.
Sends an event to the Insights middleware.
Searches for values in the list.
Whether the values are from an index search.
Whether a refinement can be applied.
Whether the Show more button can be activated, meaning there are enough
additional items to display, or already displaying over the
limit
items.Whether the menu is displaying all the menu items.
Toggles the number of values displayed between
limit
and showMoreLimit
.