UI libraries / React InstantSearch / Widgets

This is the React InstantSearch v7 documentation. React InstantSearch v7 is the latest version of React InstantSearch and the stable version of React InstantSearch Hooks.

If you were using React InstantSearch v6, you can upgrade to v7.

If you were using React InstantSearch Hooks, you can still use the React InstantSearch v7 documentation, but you should check the upgrade guide for necessary changes.

If you want to keep using React InstantSearch v6, you can find the archived documentation.

Signature
<Configure {...searchParameters} />
Import
1
import { Configure } from 'react-instantsearch';

About this widget

<Configure> is a renderless component that lets you forward search parameters to Algolia.

Any prop you pass to this component is forwarded as a search parameter to Algolia.

You can also create your own UI with useConfigure().

Examples

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import React from 'react';
import algoliasearch from 'algoliasearch/lite';
import { InstantSearch, Configure } from 'react-instantsearch';

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

function App() {
  return (
    <InstantSearch indexName="instant_search" searchClient={searchClient}>
      <Configure
        analytics={false}
        filters="free_shipping:true"
        hitsPerPage={40}
      />
    </InstantSearch>
  );
}

Props

Parameter Description
...searchParameters
type: SearchParameters

A list of search parameters to enable.

1
2
3
4
5
<Configure
  analytics={false}
  filters="free_shipping:true"
  hitsPerPage={40}
/>

Hook

React InstantSearch let you create your own UI for the <Configure> widget with useConfigure(). Hooks provide APIs to access the widget state and interact with InstantSearch.

The useConfigure() Hook accepts parameters and returns APIs.

Usage

First, create your React component:

import { useConfigure } from 'react-instantsearch';

function CustomConfigure(props) {
  const { refine } = useConfigure(props);

  return null;
}

Then, render the widget:

<CustomConfigure {...searchParameters} />

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 to avoid rendering endlessly (for example, with useCallback()). Objects and arrays are memoized; you don’t need to stabilize them.

Parameter Description
...searchParameters
type: SearchParameters

A list of search parameters to enable.

1
2
3
4
5
const configureApi = useConfigure({
  hitsPerPage: 4,
  analytics: false,
  distinct: true,
});

APIs

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

Parameter Description
refine
type: (value: SearchParameters) => void

Replaces the provided search parameters with new ones.

Example

1
2
3
4
5
6
7
8
import React from 'react';
import { useConfigure } from 'react-instantsearch';

function CustomConfigure(props) {
  useConfigure(props);

  return null;
}
Did you find this page helpful?