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
<RangeInput>
is a widget to let users select a numeric range using minimum and maximum inputs.
You can also create your own UI with
useRange
.Requirements
Theattribute
provided to the widget must be in attributes for faceting,
either on the dashboard or using the attributesForFaceting
parameter with the API.
The values of the attribute must be numbers, not strings.
Examples
JavaScript
Props
The name of the attribute in the records.
JavaScript
The minimum value for the input.
When not provided,
the minimum value is automatically computed by Algolia from the data in the index.
JavaScript
The maximum value for the input.
When not provided, the maximum value is automatically computed by Algolia from the data in the index.
JavaScript
The number of digits to use after the decimal point.
JavaScript
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.form
. The form element.label
. Each label element.input
. Each input element.inputMin
. The minimum input element.inputMax
. The maximum input element.separator
. The separator element between inputs.submit
. The submit button.
JavaScript
A mapping of keys to translation values.
separatorElementText
. The text for the separator element between the minimum and maximum inputs.submitButtonText
. The text for the submit 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<RangeInput>
widget with useRange
.
Hooks provide APIs to access the widget state and interact with InstantSearch.
The useRange
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.
JavaScript
The minimum value for the input.
When not provided, the minimum value is automatically computed by Algolia from the data in the index.
JavaScript
The maximum value for the input.
When not provided, the maximum value is automatically computed by Algolia from the data in the index.
JavaScript
The number of digits to use after the decimal point.
JavaScript
APIs
Hooks return APIs, such as state and functions. You can use them to build your UI and interact with React InstantSearch.The current value for the refinement,
with
start[0]
as the minimum value and start[1]
as the maximum value.TypeScript
The current available value for the range.
TypeScript
Whether users can refine further.
Sets a range to filter the results on.
Both values are optional, and default to the higher and lower bounds.
You can use
undefined
to remove a previously set bound or to set an infinite bound.JavaScript
Sends an event to the Insights middleware.