The <LookingSimilar> component displays recommendations for products similar to a reference item.
Import
import { LookingSimilar } from 'react-instantsearch';
Props
The object IDs to find similar items for.<LookingSimilar objectIDs={['product-123']} />
Maximum number of recommendations to display.<LookingSimilar objectIDs={['product-123']} limit={5} />
Threshold for the similarity score.<LookingSimilar objectIDs={['product-123']} threshold={0.5} />
Additional query parameters for the recommendation request.<LookingSimilar
objectIDs={['product-123']}
queryParameters={{
analytics: true,
}}
/>
Fallback parameters when not enough recommendations are found.<LookingSimilar
objectIDs={['product-123']}
fallbackParameters={{
filters: 'available:true',
}}
/>
Whether to escape HTML in the results.
Transform the recommendation items before displaying them.<LookingSimilar
objectIDs={['product-123']}
transformItems={(items) =>
items.map((item) => ({
...item,
name: item.name.toUpperCase(),
}))
}
/>
Custom component to render each recommendation item.<LookingSimilar
objectIDs={['product-123']}
itemComponent={({ item }) => (
<div>
<img src={item.image} alt={item.name} />
<h4>{item.name}</h4>
<p>${item.price}</p>
</div>
)}
/>
Custom component to render the header.
Custom component to render when there are no recommendations.
Custom component to control the layout of items.
CSS classes to customize the component styling.
Example
import { InstantSearch, LookingSimilar } from 'react-instantsearch';
import { liteClient as algoliasearch } from 'algoliasearch/lite';
const searchClient = algoliasearch(
'YourApplicationID',
'YourSearchOnlyAPIKey'
);
function ProductPage({ productId }) {
return (
<InstantSearch searchClient={searchClient} indexName="products">
<LookingSimilar
objectIDs={[productId]}
limit={4}
itemComponent={({ item }) => (
<div className="product-card">
<img src={item.image} alt={item.name} />
<h4>{item.name}</h4>
<p>${item.price}</p>
<button>View Details</button>
</div>
)}
/>
</InstantSearch>
);
}