Upgrade from Recommend React to React InstantSearch
The Recommend widgets are part of React InstantSearch. Learn how you can upgrade from Recommend React.
The components for displaying recommendations are part of React InstantSearch, starting with version 7.9.0. The Algolia JavaScript API client supports the Recommend API starting with version 4.23.2. With this, you can integrate recommendations seamlessly into your React InstantSearch app, without having to install additional packages.
Packages
Add the react-instantsearch
and algoliasearch
packages to your project,
and remove the @algolia/recommend
and @algolia/recommend-js
packages:
Imports
Import the Recommend components from React InstantSearch:
Some imports are no longer available:
- The
<TrendingFacets>
component - The
useTrendingFacets()
Hook - The
useRecommendations()
Hook - The
<Recommend>
context provider
For more information, see Components and Hooks.
Usage
Recommend widget must be children of the instantsearch component. Pass the API client and index name to the
InstantSearch` component:
Components
Recommend React | React InstantSearch | Changes |
---|---|---|
<FrequentlyBoughtTogether> | frequently-bought-together | Prop changes |
<RelatedProducts> | related-products | Prop changes |
<TrendingItems> | trending-items | Prop changes |
<TrendingFacets> | Removed | Alternative |
<LookingSimilar> | looking-similar | Prop changes |
<Recommend> | Removed | Alternative |
Changes for <FrequentlyBoughtTogether>
Move recommendClient
and indexName
to <InstantSearch>
The frequently-bought-together
component no longer needs recommendClient
and indexName
props.
Instead, pass a searchChlient
and the ìndexName
to instantsearch
.
Replace children
and view
with the layoutComponent
prop or the useFrequentlyBoughtTogether()
Hook
The frequently-bought-together
component no longer provides children
and view
props.
To fully customize the UI, use either the layoutComponent
prop or the frequently-bought-together` Hook instead.
Layout
Hook
Replace fallbackComponent
with emptyComponent
The emptyComponent
prop replaces the fallbackComponent
prop.
Replace maxRecommendations
with limit
The limit
prop replaces the maxRecommendations
prop.
Remove environment
The environment
prop is no longer needed.
Replace classNames
The classNames
keys have changed.
Changes for <RelatedProducts>
Move recommendClient
and indexName
to <InstantSearch>
The related-products
component no longer needs recommendClient
and indexName
props. Instead, pass a searchChlient
and the ìndexName
to instantsearch
.
Replace children
and view
with the layoutComponent
prop or the useRelatedProducts()
Hook
The related-products
component no longer provides children
and view
props.
To fully customize the UI, use either the layoutComponent
prop or the related-products
Hook instead.
Layout
Hook
Replace fallbackComponent
with emptyComponent
The emptyComponent
prop replaces the fallbackComponent
prop.
Replace maxRecommendations
with limit
The limit
prop replaces the maxRecommendations
prop.
The related-products
component now takes an optional maxRecommendations
prop which replaces limit
.
Remove environment
The environment
prop is no longer needed.
Replace classNames
The classNames
keys have changed.
Changes for <TrendingItems>
Move recommendClient
and indexName
to <InstantSearch>
The trending-items
component no longer needs recommendClient
and indexName
props.
Instead, pass a searchChlient
and the ìndexName
to instantsearch
.
Replace children
and view
with the layoutComponent
prop or the useTrendingItems()
Hook
The trending-items
component no longer provides children
and view
props.
To fully customize the UI, use either the layoutComponent
prop or the trending-items
Hook instead.
Layout
Hook
Replace fallbackComponent
with emptyComponent
The emptyComponent
prop replaces the fallbackComponent
prop.
Replace maxRecommendations
with limit
The limit
prop replaces the maxRecommendations
prop.
Remove environment
The environment
prop is no longer needed.
Replace classNames
The classNames
keys have changed.
Alternative for <TrendingFacets>
The <TrendingFacets>
component isn’t available in React InstantSearch.
If you need it, use the <TrendingFacets>
component from the deprecated Recommend React library.
Changes for <LookingSimilar>
Move recommendClient
and indexName
to <InstantSearch>
The looking-similar
component no longer needs recommendClient
and indexName
props.
Instead, pass a searchChlient
and the ìndexName
to instantsearch
.
Replace children
and view
with the layoutComponent
prop or the useLookingSimilar()
Hook
The looking-similar
component no longer provides children
and view
props.
To fully customize the UI, use either the layoutComponent
prop or the looking-similar
Hook instead.
Layout
Hook
Replace fallbackComponent
with emptyComponent
The emptyComponent
prop replaces the fallbackComponent
prop.
Replace maxRecommendations
with limit
The limit
prop replaces the maxRecommendations
prop.
Remove environment
The environment
prop is no longer needed.
Replace classNames
The classNames
keys have changed.
Hooks
Recommend React | React InstantSearch | Changes |
---|---|---|
useFrequentlyBoughtTogether() | frequently-bought-together | Prop changes |
useRelatedProducts() | related-products | Prop changes |
useTrendingItems() | trending-items | Prop changes |
useTrendingFacets() | Removed | Alternative |
useLookingSimilar() | looking-similar | Prop changes |
useRecommendations() | Removed | Alternative |
Changes for useFrequentlyBoughtTogether()
Move recommendClient
and indexName
to <InstantSearch>
The frequently-bought-together
Hook no longer needs recommendClient
and indexName
props.
Instead, pass a searchChlient
and the ìndexName
to instantsearch
.
Replace recommendations
with items
The frequently-bought-together
Hook returns recommendations under the items
key instead of recommendations
.
Changes for useRelatedProducts()
Move recommendClient
and indexName
to <InstantSearch>
The related-products
Hook no longer needs recommendClient
and indexName
props.
Instead, pass a searchChlient
and the ìndexName
to instantsearch
.
Replace recommendations
with items
The related-products
Hook returns recommendations under the items
key instead of recommendations
.
Changes for useTrendingItems()
Move recommendClient
and indexName
to <InstantSearch>
The trending-items
Hook no longer needs recommendClient
and indexName
props.
Instead, pass a searchChlient
and the ìndexName
to instantsearch
.
Replace recommendations
with items
The trending-items
Hook returns recommendations under the items
key instead of recommendations
.
Alternative for useTrendingFacets()
The useTrendingFacets()
Hook isn’t available in React InstantSearch.
If you need it, use the useTrendingFacets()
Hook from the deprecated Recommend React library.
Alternative for useRecommendations()
The useRecommendations()
Hook isn’t available in React InstantSearch.
Instead, use the dedicated Hooks for each Recommend model.
Changes for useLookingSimilar()
Move recommendClient
and indexName
to <InstantSearch>
The looking-similar
Hook no longer needs recommendClient
and indexName
props.
Instead, pass a searchChlient
and the ìndexName
to instantsearch
.
Replace recommendations
with items
The looking-similar
Hook returns recommendations under the items
key instead of recommendations
.
Remove <Recommend>
context provider
The <Recommend>
context provider is no longer necessary to batch requests.
Remove it from your implementation.
HorizontalSlider
The HorizontalSlider
component is now available in React InstantSearch as the Carousel
component.
For Carousel
props, check the API reference:
<FrequentlyBoughtTogether>
<RelatedProducts>
<TrendingItems>
<LookingSimilar>
Was this page helpful?