Skip to main content
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

See this widget in action

Preview this widget and its behavior.

About this widget

<SearchBox> is a widget to let users perform a text-based . The search box usually is the main entry point to start the search on an InstantSearch page. You typically place it at the top of a search experience so that users can start searching right away.
You can also create your own UI with useSearchBox.

Examples

JavaScript

Props

string
The placeholder text of the input.
JavaScript
(query: string, search: (value: string) => void) => void
Function called every time the query changes. It takes two parameters:
  • query: The current query.
  • search: The function to trigger the search.
This prop can be useful if you need to:
  • Debounce searches to regulate requests.
  • Programmatically alter the query before sending it to Algolia.
When using this prop, you’re responsible for triggering the search with search. If you don’t call this function, no search is triggered to Algolia.
boolean
default:false
since: v7.5.4
Whether to update the search state in the middle of a composition session. This is useful when users need to search using non-latin characters.
JavaScript
boolean
default:true
Whether to make a search on every change to the query. If false, new searches are only triggered by clicking the search button or by pressing the Enter key while focusing the search box.
JavaScript
boolean
default:false
Whether to show an AI Mode button in the search box. When users click this button, it opens the Chat widget and sends the current query.To use this prop, add a <Chat> widget on the same index. For an end-to-end walkthrough, see Build an AI-powered search experience.
JavaScript
boolean
default:false
Whether the input should be autofocused.
JavaScript
(event: React.FormEvent<HTMLFormElement>) => void
A callback to run when submitting the form of the search box.
JavaScript
(props: IconProps) => JSX.Element
A component to replace the icon in the submit button.The component receives the passed classNames prop.
JavaScript
(props: IconProps) => JSX.Element
A component to replace the icon in the reset button.The component receives the passed classNames prop.
JavaScript
(props: IconProps) => JSX.Element
A component to replace the loading icon.The component receives the passed classNames prop.
JavaScript
(props: IconProps) => JSX.Element
A component to replace the icon in the AI Mode button.The component receives the passed classNames prop.
JavaScript
Partial<SearchBoxClassNames>
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.
  • form. The form element.
  • input. The input element.
  • submit. The submit button.
  • reset. The reset button.
  • loadingIndicator. The loading indicator element.
  • submitIcon. The submit icon.
  • resetIcon. The reset icon.
  • loadingIcon. The loading icon.
  • aiModeButton. The AI mode button.
  • aiModeIcon. The AI mode icon.
  • aiModeLabel. The AI mode label.
JavaScript
Partial<SearchBoxTranslations>
A dictionary of translations to customize the UI text and support internationalization.
  • submitButtonTitle. The submit button’s title.
  • resetButtonTitle. The reset button’s title.
  • aiModeButtonTitle. The AI mode button’s title.
JavaScript
React.ComponentProps<'div'>
Any <div> prop to forward to the root element of the widget.
JavaScript

Hook

React InstantSearch let you create your own UI for the <SearchBox> widget with useSearchBox. Hooks provide APIs to access the widget state and interact with InstantSearch. The useSearchBox Hook accepts parameters and returns APIs. It must be used inside the <InstantSearch> component.

Usage

First, create your React component:
JavaScript
Then, render the widget:
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.
(query: string, hook: (value: string) => void) => void
Function called every time the query changes.See queryHook for detail.

APIs

Hooks return APIs, such as state and functions. You can use them to build your UI and interact with React InstantSearch.
string
The query from the last search.
(value: string) => void
Sets a new query and searches.
() => void
Clears the query and searches.
boolean
deprecated
Use status from useInstantSearch instead.
Whether the search results take more than a certain time to come back from Algolia servers.This can be configured on <InstantSearch> with the stalledSearchDelay props which defaults to 200 ms.

Example

Last modified on July 22, 2026