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
<Breadcrumb>
is a widget that displays navigation links to see where the current page is in relation to the facet’s hierarchy.
It reduces the number of actions a user needs to take to get to a higher-level page and improves the discoverability of the app or website’s sections and pages.
It’s commonly used for websites with lot of data, organized into categories with subcategories.
You can also create your own UI with
useBreadcrumb
.Requirements
The objects to use in the breadcrumb must follow this structure:JSON
JSON
- Decide on an appropriate facet hierarchy
- Determine your
attributes
for faceting from the dashboard or with an API client - Display the UI with the hierarchical menu widget.
>
(with spaces),
but you can use a different one by using the separator option.
If there is also a <HierarchicalMenu>
on the page,
it must follow the same configuration.
Examples
JavaScript
Props
An array of attributes to generate the breadcrumb.
JavaScript
The path to use if the first level isn’t the root level.Make sure to also include the root path in your UI state,
for example, by setting
initialUiState
or calling setUiState
.JavaScript
The level separator used in the records.
JavaScript
A function that receives the list of items before they are displayed.
It should return a new array with the same structure.
Use this to transform, filter, or reorder the items.The function also has access to the full
results
data,
including all standard response parameters
and parameters from the helper,
such as disjunctiveFacetsRefinements
.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.list
. The list element.item
. Each item element.selectedItem
. The selected item element.separator
. The separator between items.link
. The link of each item.
JavaScript
A dictionary of translations to customize the UI text and support internationalization.
rootElementText
. The text for the breadcrumb’s starting point (for example, “Home page”).
JavaScript
Any
<div>
prop to forward to the root element of the widget.JavaScript
Hook
React InstantSearch lets you create your own UI for the<Breadcrumb>
widget with useBreadcrumb
.
Hooks provide APIs to access the widget state and interact with InstantSearch.
The useBreadcrumb
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.An array of attributes to generate the breadcrumb.
JavaScript
The path to use if the first level isn’t the root level.Make sure to also include the root path in your UI state,
for example, by setting
initialUiState
or calling setUiState
.JavaScript
The level separator used in the records.
JavaScript
A function that receives the list of items before they are displayed.
It should return a new array with the same structure.
Use this to transform, filter, or reorder the items.The function also has access to the full
results
data,
including all standard response parameters
and parameters from the helper,
such as disjunctiveFacetsRefinements
.APIs
The list of available options, with each option:
label: string
. The label of the category or subcategory.value: string
. The value of breadcrumb item.
TypeScript
Indicates if search state can be refined.
Sets the path of the hierarchical filter and triggers a new search.
Generates a URL of the next state of a clicked item. The special value
null
is used for the root item of the breadcrumb and returns an empty URL.