React InstantSearch is an open source library for building search interfaces.
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.
InstantSearch focuses on enhancing your frontend with primitives that you can combine to create unique search interfaces.InstantSearch supports server-side rendering and offers full routing capabilities.
Open CodeSandbox
Run and edit the What is React InstantSearch? example in CodeSandbox.
InstantSearch offers three levels of increasing control over your UI:
Start with a predefined widget that you can configure and style with CSS.
To change the render output of a widget, use Hooks to render what you want.
To implement something that doesn’t exist, create a custom Hook.
The recommended way to use InstantSearch is with its predefined widgets such as SearchBox.
InstantSearch includes a set of widgets that are most often used in search experiences.
Widgets provide features and a rendered output.
You can place them anywhere on your UI, configure them, and style them with CSS.For example, add the RefinementList` widget and ask it to show a list of brands, so your users can refine their search using those brands.
The InstantSearch wrapper communicates between your app and Algolia.
This is where you add all the widgets.
It accepts a search client and an name.Refinement list widget
The predefined widgets in React InstantSearch are compatible with the default CSS theme:Default theme previewFor more information, see Style your widgets.
If you use Hooks and you want to use the default theme in your app,
follow the markup from the predefined widgets and use the InstantSearch class names.
Algolia’s predefined widgets, with their fixed behavior and output, may not fully meet your requirements.
For example, you might want to use React InstantSearch with a component library like Material UI or render to a non-DOM target like React Native.To address these limitations, use Hooks to construct the UI you want:
When you provide a function to Hooks,
make sure to pass a stable reference to avoid rendering endlessly
(for example, with useCallback).
You don’t need to stabilize objects and arrays, because React reuses them between renders unless you create new ones.
Use useConnector to turn the connector into a Hook:
import { useConnector } from "react-instantsearch";import { connectMyWidget } from "./connectMyWidget";export function useMyWidget(props) { return useConnector(connectMyWidget, props);}
import { useMyWidget } from "./useMyWidget";export function MyComponent(props) { const data = useMyWidget(props); // Render based on the data returned by the Hook return null;}
import { liteClient as algoliasearch } from "algoliasearch/lite";import { InstantSearch } from "react-instantsearch";import { MyComponent } from "./MyComponent";const searchClient = algoliasearch("undefined", "undefined");function App() { return ( <InstantSearch searchClient={searchClient} indexName="instant_search"> <MyComponent /> </InstantSearch> );}
You can now use your new Hook and component anywhere within InstantSearch.