React InstantSearch
React InstantSearch is an open-source React library developed by Algolia, designed to help developers quickly create fast, dynamic search user interfaces. It leverages Algolia's powerful search API to deliver an instant search experience, adhering to modern React principles for component-based development. The current stable version is 7.29.0, with releases occurring regularly, typically monthly, as seen by the March 2026 update. Key differentiators include its highly customizable component architecture, seamless integration with the Algolia ecosystem, and a focus on best practices for search UI design. It's part of the broader InstantSearch family, offering similar experiences for other frameworks like Vue and vanilla JavaScript. For environments without DOM access, such as React Native, `react-instantsearch-core` is the appropriate alternative.
Common errors
-
TypeError: Cannot read properties of undefined (reading 'init') OR searchClient is not a function
cause The `searchClient` prop passed to `<InstantSearch>` is either undefined, null, or not a valid Algolia search client instance.fixVerify that `algoliasearch` is correctly imported (using `liteClient` for browser) and initialized with valid App ID and Search API Key. Ensure the `searchClient` variable is defined before being passed as a prop. -
Error: No index found. Please make sure to pass an 'indexName' prop to the <InstantSearch> component.
cause The `indexName` prop is missing or empty on the `<InstantSearch>` component.fixAdd the `indexName` prop to your `<InstantSearch>` component, specifying the name of your Algolia index (e.g., `<InstantSearch indexName="your_index_name" searchClient={searchClient}>`). -
Error: Hooks can only be called inside of the body of a function component.
cause This error typically indicates that React InstantSearch components are being used with an outdated React version (pre-16.8) or outside of a functional React component context.fixUpgrade your `react` and `react-dom` packages to version 16.8.0 or higher. Ensure all React InstantSearch components are rendered within a functional React component.
Warnings
- breaking React InstantSearch versions 6 and above are designed for ESM environments. Using CommonJS `require()` or older build setups may lead to issues.
- breaking React InstantSearch relies on React Hooks, introduced in React 16.8. Older versions of React will not be compatible.
- gotcha React InstantSearch components provide functionality but minimal styling by default. You need to import a theme or provide your own CSS.
- gotcha Using the full `algoliasearch` client bundle (`import algoliasearch from 'algoliasearch';`) in a browser environment can unnecessarily increase your bundle size.
Install
-
npm install react-instantsearch -
yarn add react-instantsearch -
pnpm add react-instantsearch
Imports
- InstantSearch
const InstantSearch = require('react-instantsearch');import { InstantSearch } from 'react-instantsearch'; - SearchBox
import SearchBox from 'react-instantsearch/lib/SearchBox';
import { SearchBox } from 'react-instantsearch'; - Hits
import { connectHits } from 'react-instantsearch/lib/connectors';import { Hits } from 'react-instantsearch'; - algoliasearch client
import algoliasearch from 'algoliasearch';
import { liteClient as algoliasearch } from 'algoliasearch/lite';
Quickstart
import React from 'react';
import ReactDOM from 'react-dom/client';
import { liteClient as algoliasearch } from 'algoliasearch/lite';
import { InstantSearch, SearchBox, Hits } from 'react-instantsearch';
import 'instantsearch.css/themes/algolia.css'; // Optional: for basic styling
// Replace with your Algolia App ID and Search API Key
const searchClient = algoliasearch(
process.env.NEXT_PUBLIC_ALGOLIA_APP_ID ?? 'latency',
process.env.NEXT_PUBLIC_ALGOLIA_SEARCH_API_KEY ?? '6be0576ff61c053d5f9a3225e2a90f76'
);
const App = () => (
<InstantSearch indexName="bestbuy" searchClient={searchClient}>
<h1>React InstantSearch Example</h1>
<SearchBox placeholder="Search products..." />
<Hits />
</InstantSearch>
);
const root = ReactDOM.createRoot(document.getElementById('root')!);
root.render(<App />);