Recombee Docs
Visit recombee.comStart Free
docs20User Documentation
adminuiAdmin UI
reql32ReQL
codeAPI Clients & Integrations
cookhatScenario Recipes
suitcaseMisc
Widget SDKs / Carousel / Carousel Widget (React)

Carousel Widget (React)

A React component widget that displays a horizontal scroll of recommended items, designed to increase engagement through visually appealing item rotation.

Use this library when you want to render a widget and you are using React and JSX in your project.

This widget library is version 0.0.5 and the API can change. Please specify exact version when installing.

Install @recombee/carousel-widget-react@0.0.5 and recombee-js-api-client packages using your preferred NPM package manager. This example is using pnpm.

pnpm add @recombee/carousel-widget-react@0.0.5 recombee-js-api-client
Copy

The widget loads recommendation data using Recombee API Client. Here is how to initialize the client with necessary configuration for a specific database:

import { class ApiClient
Client for sending requests to Recombee and getting replies
ApiClient
} from "recombee-js-api-client";
const const DATABASE_ID: "[database-id]"DATABASE_ID = "[database-id]"; const const PUBLIC_TOKEN: "[database-public-token]"PUBLIC_TOKEN = "[database-public-token]"; const const REGION: "[database-region]"REGION = "[database-region]"; export const const apiClient: ApiClientapiClient = new new ApiClient(databaseId: string, publicToken: string, options?: ApiClientOptions): ApiClient
@paramdatabaseId - ID of your database.@parampublicToken - Corresponding public token.@paramoptions - Other custom options.
ApiClient
(const DATABASE_ID: "[database-id]"DATABASE_ID, const PUBLIC_TOKEN: "[database-public-token]"PUBLIC_TOKEN, {
region?: string | undefinedregion: const REGION: "[database-region]"REGION, });
Copy

The Database Public Token can be found in the Admin UI Database Settings Page.

The widget also needs to be provided a createRequest function, which instantiates a client request class to define which data to pull from the database. Use Scenario ID which can be found on Admin GUI Database Scenarios Page.

import { type type CreateRequestFunction = (options: FetchContentOptions) => Request
Factory for creating Recombee API Request to load data into a Widget.
@public
CreateRequestFunction
} from "@recombee/carousel-widget-react";
import { class RecommendItemsToUser
Based on the user's past interactions (purchases, ratings, etc.) with the items, recommends top-N items that are most likely to be of high value for the given user. The most typical use cases are recommendations on the homepage, in some "Picked just for you" section, or in email. The returned items are sorted by relevance (the first item being the most relevant). Besides the recommended items, also a unique `recommId` is returned in the response. It can be used to: - Let Recombee know that this recommendation was successful (e.g., user clicked one of the recommended items). See [Reported metrics](https://docs.recombee.com/admin_ui.html#reported-metrics). - Get subsequent recommended items when the user scrolls down (*infinite scroll*) or goes to the next page. See [Recommend Next Items](https://docs.recombee.com/api.html#recommend-next-items). It is also possible to use POST HTTP method (for example in the case of a very long ReQL filter) - query parameters then become body parameters.
RecommendItemsToUser
} from "recombee-js-api-client";
const const createRequest: CreateRequestFunctioncreateRequest: type CreateRequestFunction = (options: FetchContentOptions) => Request
Factory for creating Recombee API Request to load data into a Widget.
@public
CreateRequestFunction
= ({ count: number
Number of items to fetch for the widget. Pass it to the appropriate Request constructor.
count
}) => {
const const SCENARIO_ID: "recommend-items-to-user"SCENARIO_ID = "recommend-items-to-user"; return new
new RecommendItemsToUser(userId: string, count: number, optional?: {
    scenario?: string;
    cascadeCreate?: boolean;
    returnProperties?: boolean;
    includedProperties?: string[];
    filter?: string;
    booster?: string;
    logic?: string | object;
    diversity?: number;
    minRelevance?: string;
    rotationRate?: number;
    rotationTime?: number;
    expertSettings?: {
        [key: string]: unknown;
    };
    returnAbGroup?: boolean;
}): RecommendItemsToUser
@paramuserId - ID of the user for whom personalized recommendations are to be generated.@paramcount - Number of items to be recommended (N for the top-N recommendation).@paramoptional - Optional parameters given as an object.
RecommendItemsToUser
(userId, count: number
Number of items to fetch for the widget. Pass it to the appropriate Request constructor.
count
, {
scenario?: string | undefined
Scenario defines a particular application of recommendations. It can be, for example, "homepage", "cart", or "emailing".
scenario
: const SCENARIO_ID: "recommend-items-to-user"SCENARIO_ID,
cascadeCreate?: boolean | undefined
If the user does not exist in the database, returns a list of non-personalized recommendations and creates the user in the database. This allows, for example, rotations in the following recommendations for that user, as the user will be already known to the system.
cascadeCreate
: true,
returnProperties?: boolean | undefined
With `returnProperties=true`, property values of the recommended items are returned along with their IDs in a JSON dictionary. The acquired property values can be used to easily display the recommended items to the user.
returnProperties
: true,
}); };
Copy

Please ensure that you provide the user ID (typically obtained from your existing user tracking system), along with other relevant parameters - such as an item ID or Item Segment ID - depending on the specific type of recommendation request.

The widget in this example uses the DefaultItem component to render each recommendation in a consistent layout.

The resulting widget is inserted into the element specified by the container field.

Values of the recommended items - such as title, image URL, or link URL - are obtained from the API response and accessed via props.result?.values.

Ensure that returnProperties: true is set in the request, and optionally use includedProperties to control which item properties are returned.

import {
  const CarouselWidget: React.FunctionComponent<CarouselWidgetProps>
Carousel widget React Component. See {@link CarouselWidgetProps } for configuration options.
@public
CarouselWidget
,
const DefaultItem: ((props: DefaultItemProps) => React.JSX.Element) & {
    displayName: string;
}
Default Item component provided for basic usage.
@public
DefaultItem
,
const ItemImage: React.FunctionComponent<ItemImageProps>
Item image component
@public
ItemImage
,
function addRecommIdQueryParam(url: string, recommId: string | undefined): string
Utility function to append `recombee_recomm_id` parameter to an url string. For usage in widget template to construct item link URL.
@public
addRecommIdQueryParam
,
} from "@recombee/carousel-widget-react"; import "@recombee/carousel-widget-react/dist/styles.css"; export default () => { return ( <const CarouselWidget: React.FunctionComponent<CarouselWidgetProps>
Carousel widget React Component. See {@link CarouselWidgetProps } for configuration options.
@public
CarouselWidget
WidgetConfigurationBase<CreateRequestFunction>.apiClient: ApiClient
Instance of Recombee JS API Client. See {@link file://./#client-initialization Example } .
@public
apiClient
={const apiClient: ApiClientapiClient}
WidgetConfigurationBase<CreateRequestFunction>.createRequest: CreateRequestFunction
Request factory function. See {@link file://./#client-initialization Quick Example } or visit {@link file:///api API Reference } for overview of available requests.
@public
createRequest
={const createRequest: CreateRequestFunctioncreateRequest}
type ItemComponent: (props: {
    state: CarouselWidgetState;
    result?: Recommendation;
}) => React.ReactNode
A component rendering a single recommended item.
@public
ItemComponent
={(
props: {
    state: CarouselWidgetState;
    result?: Recommendation;
}
props
) => (
<
const DefaultItem: ((props: DefaultItemProps) => React.JSX.Element) & {
    displayName: string;
}
Default Item component provided for basic usage.
@public
DefaultItem
DefaultItemProps.href?: string | null | undefined
Item link URL.
@public
href
={function addRecommIdQueryParam(url: string, recommId: string | undefined): string
Utility function to append `recombee_recomm_id` parameter to an url string. For usage in widget template to construct item link URL.
@public
addRecommIdQueryParam
(
`${
props: {
    state: CarouselWidgetState;
    result?: Recommendation;
}
props
.result?: Recommendation | undefinedresult?.
values?: {
    [key: string]: any;
} | undefined
Item properties
@public
values
?.link}`,
props: {
    state: CarouselWidgetState;
    result?: Recommendation;
}
props
.state: CarouselWidgetStatestate.CarouselWidgetState.recommId: string | undefined
Id of recommendation response from which the items originated.
@public
recommId
,
)} DefaultItemProps.image?: React.ReactNode
Item Image element.
@public
image
={
<const ItemImage: React.FunctionComponent<ItemImageProps>
Item image component
@public
ItemImage
src?: string | null | undefined
Image URL
@public
src
={`${
props: {
    state: CarouselWidgetState;
    result?: Recommendation;
}
props
.result?: Recommendation | undefinedresult?.
values?: {
    [key: string]: any;
} | undefined
Item properties
@public
values
?.images?.[0]}`}
width?: number | undefined
Image width in pixels
@public
width
={600}
height?: number | undefined
Image height in pixels
@public
height
={400}
/> } DefaultItemProps.labelContent?: React.ReactNode
Item content above title. Sets the entire content of an item aside from an image.
@public
labelContent
={`${
props: {
    state: CarouselWidgetState;
    result?: Recommendation;
}
props
.result?: Recommendation | undefinedresult?.
values?: {
    [key: string]: any;
} | undefined
Item properties
@public
values
?.genres?.join(", ")}`}
DefaultItemProps.title?: React.ReactNode
Item title.
@public
title
={`${
props: {
    state: CarouselWidgetState;
    result?: Recommendation;
}
props
.result?: Recommendation | undefinedresult?.
values?: {
    [key: string]: any;
} | undefined
Item properties
@public
values
?.title}`}
DefaultItemProps.highlightedContent?: React.ReactNode
Item content under title. Sets the entire content of an item aside from an image.
@public
highlightedContent
={`${
props: {
    state: CarouselWidgetState;
    result?: Recommendation;
}
props
.result?: Recommendation | undefinedresult?.
values?: {
    [key: string]: any;
} | undefined
Item properties
@public
values
?.year}`}
/> )} /> ); };
Copy

The addRecommIdQueryParam utility function is used to append the recommendation ID to the item's URL as the recombee_recomm_id query parameter.

This enables you to report successful (clicked) recommendations back to Recombee for improved tracking and performance optimization.

Recombee Widgets are designed to be styling-agnostic. You can fully customize their appearance using your own CSS by passing class names through customization properties.

In these docs examples, we use utility classes from Tailwind CSS for styling.

Class names for internal elements and custom components are passed as props and applied by the widget during rendering. The default structure of the Basic Example widget is illustrated below (pseudo-code):

<div class="{className}">
  <div class="{contentClassName}">
    <div class="{itemWrapperClassName}">
      <ItemComponent />
    </div>
    <div class="{itemWrapperClassName}">
      <ItemComponent />
    </div>
    <div class="{itemWrapperClassName}">
      <ItemComponent />
    </div>
    ... more items ...
  </div>
  <ArrowComponent arrowDirection="left" />
  <ArrowComponent arrowDirection="right" />
</div>
Copy

This is handy to understand how to customize the widget to full potential.

import {
  const CarouselWidget: React.FunctionComponent<CarouselWidgetProps>
Carousel widget React Component. See {@link CarouselWidgetProps } for configuration options.
@public
CarouselWidget
,
const DefaultItem: ((props: DefaultItemProps) => React.JSX.Element) & {
    displayName: string;
}
Default Item component provided for basic usage.
@public
DefaultItem
,
const ItemImage: React.FunctionComponent<ItemImageProps>
Item image component
@public
ItemImage
,
function addRecommIdQueryParam(url: string, recommId: string | undefined): string
Utility function to append `recombee_recomm_id` parameter to an url string. For usage in widget template to construct item link URL.
@public
addRecommIdQueryParam
,
} from "@recombee/carousel-widget-react"; import "@recombee/carousel-widget-react/dist/styles.css"; export default () => { return ( <const CarouselWidget: React.FunctionComponent<CarouselWidgetProps>
Carousel widget React Component. See {@link CarouselWidgetProps } for configuration options.
@public
CarouselWidget
WidgetConfigurationBase<CreateRequestFunction>.apiClient: ApiClient
Instance of Recombee JS API Client. See {@link file://./#client-initialization Example } .
@public
apiClient
={const apiClient: ApiClientapiClient}
WidgetConfigurationBase<CreateRequestFunction>.createRequest: CreateRequestFunction
Request factory function. See {@link file://./#client-initialization Quick Example } or visit {@link file:///api API Reference } for overview of available requests.
@public
createRequest
={const createRequest: CreateRequestFunctioncreateRequest}
className?: string | undefined
Custom classes of widget wrapper element. See {@link file://./#custom-css Custom CSS } .
@public
className
="overflow-hidden rounded-lg border-[#ededed] bg-white text-[#282b30] dark:border-none dark:bg-transparent dark:text-white"
type ItemComponent: (props: {
    state: CarouselWidgetState;
    result?: Recommendation;
}) => React.ReactNode
A component rendering a single recommended item.
@public
ItemComponent
={(
props: {
    state: CarouselWidgetState;
    result?: Recommendation;
}
props
) => (
<
const DefaultItem: ((props: DefaultItemProps) => React.JSX.Element) & {
    displayName: string;
}
Default Item component provided for basic usage.
@public
DefaultItem
DefaultItemProps.classNameDisableBase?: boolean | undefined
Disables default classes of item wrapper element. There are some default class names with essential styles applied to the item wrapper element. This setting disables them as an escape hatch for customization. See {@link file://./#custom-css Custom CSS } .
@public
classNameDisableBase
DefaultItemProps.className?: string | undefined
Custom classes of item wrapper element. See {@link file://./#custom-css Custom CSS } .
@public
className
="border-b border-slate-600"
DefaultItemProps.contentWrapperClassName?: string | undefined
Custom classes of item content element. See {@link file://./#custom-css Custom CSS } .
@public
contentWrapperClassName
="text-center"
DefaultItemProps.href?: string | null | undefined
Item link URL.
@public
href
={function addRecommIdQueryParam(url: string, recommId: string | undefined): string
Utility function to append `recombee_recomm_id` parameter to an url string. For usage in widget template to construct item link URL.
@public
addRecommIdQueryParam
(
`${
props: {
    state: CarouselWidgetState;
    result?: Recommendation;
}
props
.result?: Recommendation | undefinedresult?.
values?: {
    [key: string]: any;
} | undefined
Item properties
@public
values
?.link}`,
props: {
    state: CarouselWidgetState;
    result?: Recommendation;
}
props
.state: CarouselWidgetStatestate.CarouselWidgetState.recommId: string | undefined
Id of recommendation response from which the items originated.
@public
recommId
,
)} DefaultItemProps.image?: React.ReactNode
Item Image element.
@public
image
={
<const ItemImage: React.FunctionComponent<ItemImageProps>
Item image component
@public
ItemImage
src?: string | null | undefined
Image URL
@public
src
={`${
props: {
    state: CarouselWidgetState;
    result?: Recommendation;
}
props
.result?: Recommendation | undefinedresult?.
values?: {
    [key: string]: any;
} | undefined
Item properties
@public
values
?.images?.[0]}`}
width?: number | undefined
Image width in pixels
@public
width
={600}
height?: number | undefined
Image height in pixels
@public
height
={400}
/> } DefaultItemProps.labelContent?: React.ReactNode
Item content above title. Sets the entire content of an item aside from an image.
@public
labelContent
={`${
props: {
    state: CarouselWidgetState;
    result?: Recommendation;
}
props
.result?: Recommendation | undefinedresult?.
values?: {
    [key: string]: any;
} | undefined
Item properties
@public
values
?.genres?.join(", ")}`}
DefaultItemProps.title?: React.ReactNode
Item title.
@public
title
={`${
props: {
    state: CarouselWidgetState;
    result?: Recommendation;
}
props
.result?: Recommendation | undefinedresult?.
values?: {
    [key: string]: any;
} | undefined
Item properties
@public
values
?.title}`}
DefaultItemProps.highlightedContent?: React.ReactNode
Item content under title. Sets the entire content of an item aside from an image.
@public
highlightedContent
={`${
props: {
    state: CarouselWidgetState;
    result?: Recommendation;
}
props
.result?: Recommendation | undefinedresult?.
values?: {
    [key: string]: any;
} | undefined
Item properties
@public
values
?.year}`}
/> )} /> ); };
Copy

Recombee Widgets support full customization of internal components such as the appearance of the recommended items.

You can provide your own components via props like ItemComponent to control the structure, styling, and behavior of the widget.

This flexibility allows you to adapt the widget's appearance and functionality to match your design and user experience requirements.

import { const CarouselWidget: React.FunctionComponent<CarouselWidgetProps>
Carousel widget React Component. See {@link CarouselWidgetProps } for configuration options.
@public
CarouselWidget
, const ItemImage: React.FunctionComponent<ItemImageProps>
Item image component
@public
ItemImage
} from "@recombee/carousel-widget-react";
import "@recombee/carousel-widget-react/dist/styles.css"; export default () => { return ( <const CarouselWidget: React.FunctionComponent<CarouselWidgetProps>
Carousel widget React Component. See {@link CarouselWidgetProps } for configuration options.
@public
CarouselWidget
WidgetConfigurationBase<CreateRequestFunction>.apiClient: ApiClient
Instance of Recombee JS API Client. See {@link file://./#client-initialization Example } .
@public
apiClient
={const apiClient: ApiClientapiClient}
WidgetConfigurationBase<CreateRequestFunction>.createRequest: CreateRequestFunction
Request factory function. See {@link file://./#client-initialization Quick Example } or visit {@link file:///api API Reference } for overview of available requests.
@public
createRequest
={const createRequest: CreateRequestFunctioncreateRequest}
itemWrapperClassName?: string | undefined
Custom classes of item wrapper element. See {@link file://./#custom-css Custom CSS } .
@public
itemWrapperClassName
="min-h-[240px] w-[200px]"
type ItemComponent: (props: {
    state: CarouselWidgetState;
    result?: Recommendation;
}) => React.ReactNode
A component rendering a single recommended item.
@public
ItemComponent
={(
props: {
    state: CarouselWidgetState;
    result?: Recommendation;
}
props
) => (
<React.JSX.IntrinsicElements.div: React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>div React.HTMLAttributes<HTMLDivElement>.className?: string | undefinedclassName="overflow-hidden rounded-lg border-[#ededed] bg-white text-[#282b30] dark:border-none dark:bg-transparent dark:text-white"> <React.JSX.IntrinsicElements.div: React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>div React.HTMLAttributes<HTMLDivElement>.className?: string | undefinedclassName="relative overflow-hidden bg-cover bg-no-repeat"> <const ItemImage: React.FunctionComponent<ItemImageProps>
Item image component
@public
ItemImage
src?: string | null | undefined
Image URL
@public
src
={`${
props: {
    state: CarouselWidgetState;
    result?: Recommendation;
}
props
.result?: Recommendation | undefinedresult?.
values?: {
    [key: string]: any;
} | undefined
Item properties
@public
values
?.images?.[0]}`}
width?: number | undefined
Image width in pixels
@public
width
={600}
height?: number | undefined
Image height in pixels
@public
height
={400}
/> {
props: {
    state: CarouselWidgetState;
    result?: Recommendation;
}
props
.result?: Recommendation | undefinedresult?.
values?: {
    [key: string]: any;
} | undefined
Item properties
@public
values
?.["genres"]?.includes("drama") && (
<React.JSX.IntrinsicElements.div: React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>div React.HTMLAttributes<HTMLDivElement>.className?: string | undefinedclassName="absolute top-3 left-3 bg-[#3f91ff] px-2 text-xs/[1.67] font-semibold text-white"> Drama </React.JSX.IntrinsicElements.div: React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>div> )} {
props: {
    state: CarouselWidgetState;
    result?: Recommendation;
}
props
.result?: Recommendation | undefinedresult?.
values?: {
    [key: string]: any;
} | undefined
Item properties
@public
values
?.["genres"]?.includes("science_fiction") && (
<React.JSX.IntrinsicElements.div: React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>div React.HTMLAttributes<HTMLDivElement>.className?: string | undefinedclassName="absolute top-3 left-3 bg-[#36c696] px-2 text-xs/[1.67] font-semibold text-white"> Sci-Fi </React.JSX.IntrinsicElements.div: React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>div> )} </React.JSX.IntrinsicElements.div: React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>div> <React.JSX.IntrinsicElements.div: React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>div React.HTMLAttributes<HTMLDivElement>.className?: string | undefinedclassName="p-3"> <React.JSX.IntrinsicElements.div: React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>div React.HTMLAttributes<HTMLDivElement>.className?: string | undefinedclassName="mb-1 line-clamp-4 overflow-hidden text-[14px]/[1.43] text-nowrap text-ellipsis text-[#80868f]"> {`${
props: {
    state: CarouselWidgetState;
    result?: Recommendation;
}
props
.result?: Recommendation | undefinedresult?.
values?: {
    [key: string]: any;
} | undefined
Item properties
@public
values
?.genres?.join(", ")}`}
</React.JSX.IntrinsicElements.div: React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>div> <React.JSX.IntrinsicElements.div: React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>div React.HTMLAttributes<HTMLDivElement>.className?: string | undefinedclassName="text-md mb-1 overflow-hidden text-nowrap text-ellipsis"> {`${
props: {
    state: CarouselWidgetState;
    result?: Recommendation;
}
props
.result?: Recommendation | undefinedresult?.
values?: {
    [key: string]: any;
} | undefined
Item properties
@public
values
?.title}`}
</React.JSX.IntrinsicElements.div: React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>div> <React.JSX.IntrinsicElements.div: React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>div React.HTMLAttributes<HTMLDivElement>.className?: string | undefinedclassName="line-clamp-4 pb-3 text-base text-[#3f91ff]"> {`${
props: {
    state: CarouselWidgetState;
    result?: Recommendation;
}
props
.result?: Recommendation | undefinedresult?.
values?: {
    [key: string]: any;
} | undefined
Item properties
@public
values
?.year}`}
</React.JSX.IntrinsicElements.div: React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>div> <React.JSX.IntrinsicElements.button: React.DetailedHTMLProps<React.ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>button React.HTMLAttributes<T>.className?: string | undefinedclassName="w-full rounded-lg border border-[#ededed] py-2 text-center text-[14px]/[1.43] font-medium text-[#80868f]"> Play </React.JSX.IntrinsicElements.button: React.DetailedHTMLProps<React.ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>button> </React.JSX.IntrinsicElements.div: React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>div> </React.JSX.IntrinsicElements.div: React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>div> )} /> ); };
Copy
import {
  const CarouselWidget: React.FunctionComponent<CarouselWidgetProps>
Carousel widget React Component. See {@link CarouselWidgetProps } for configuration options.
@public
CarouselWidget
,
const DefaultItem: ((props: DefaultItemProps) => React.JSX.Element) & {
    displayName: string;
}
Default Item component provided for basic usage.
@public
DefaultItem
,
const ItemImage: React.FunctionComponent<ItemImageProps>
Item image component
@public
ItemImage
,
function addRecommIdQueryParam(url: string, recommId: string | undefined): string
Utility function to append `recombee_recomm_id` parameter to an url string. For usage in widget template to construct item link URL.
@public
addRecommIdQueryParam
,
} from "@recombee/carousel-widget-react"; import "@recombee/carousel-widget-react/dist/styles.css"; export default () => { return ( <const CarouselWidget: React.FunctionComponent<CarouselWidgetProps>
Carousel widget React Component. See {@link CarouselWidgetProps } for configuration options.
@public
CarouselWidget
WidgetConfigurationBase<CreateRequestFunction>.apiClient: ApiClient
Instance of Recombee JS API Client. See {@link file://./#client-initialization Example } .
@public
apiClient
={const apiClient: ApiClientapiClient}
WidgetConfigurationBase<CreateRequestFunction>.createRequest: CreateRequestFunction
Request factory function. See {@link file://./#client-initialization Quick Example } or visit {@link file:///api API Reference } for overview of available requests.
@public
createRequest
={const createRequest: CreateRequestFunctioncreateRequest}
itemWrapperClassName?: string | undefined
Custom classes of item wrapper element. See {@link file://./#custom-css Custom CSS } .
@public
itemWrapperClassName
="min-h-[400px] w-[400px]"
ArrowComponent?: ((props: CarouselArrowProps) => React.ReactNode) | undefined
A component rendering either left or right carousel arrow
@public
ArrowComponent
={(props: CarouselArrowPropsprops) => {
if ( props: CarouselArrowPropsprops.arrowDirection: "left" | "right"
The direction of an arrow to render.
@public
arrowDirection
=== "left" &&
props: CarouselArrowPropsprops.state: CarouselWidgetState
Carousel state.
@public
state
.CarouselWidgetState.leftArrow: ArrowState
Current state of left Carousel arrow
@public
leftArrow
.isVisible: booleanisVisible
) { return ( <React.JSX.IntrinsicElements.button: React.DetailedHTMLProps<React.ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>button React.HTMLAttributes<HTMLButtonElement>.className?: string | undefinedclassName="absolute top-1/2 left-4 -translate-y-6 rounded-lg rounded-sm border border-[#ededed] bg-white px-3 py-2 text-center text-[14px]/[1.43] font-medium text-[#80868f]" React.ButtonHTMLAttributes<HTMLButtonElement>.type?: "button" | "submit" | "reset" | undefinedtype="button" React.DOMAttributes<HTMLButtonElement>.onClick?: React.MouseEventHandler<HTMLButtonElement> | undefinedonClick={props: CarouselArrowPropsprops.state: CarouselWidgetState
Carousel state.
@public
state
.CarouselWidgetState.leftArrow: ArrowState
Current state of left Carousel arrow
@public
leftArrow
.handleClick: () => voidhandleClick}
> prev </React.JSX.IntrinsicElements.button: React.DetailedHTMLProps<React.ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>button> ); } if ( props: CarouselArrowPropsprops.arrowDirection: "left" | "right"
The direction of an arrow to render.
@public
arrowDirection
=== "right" &&
props: CarouselArrowPropsprops.state: CarouselWidgetState
Carousel state.
@public
state
.CarouselWidgetState.rightArrow: ArrowState
Current state of right Carousel arrow
@public
rightArrow
.isVisible: booleanisVisible
) { return ( <React.JSX.IntrinsicElements.button: React.DetailedHTMLProps<React.ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>button React.HTMLAttributes<HTMLButtonElement>.className?: string | undefinedclassName="absolute top-1/2 right-4 -translate-y-6 rounded-lg rounded-sm border border-[#ededed] bg-white px-3 py-2 text-center text-[14px]/[1.43] font-medium text-[#80868f]" React.ButtonHTMLAttributes<HTMLButtonElement>.type?: "button" | "submit" | "reset" | undefinedtype="button" React.DOMAttributes<HTMLButtonElement>.onClick?: React.MouseEventHandler<HTMLButtonElement> | undefinedonClick={props: CarouselArrowPropsprops.state: CarouselWidgetState
Carousel state.
@public
state
.CarouselWidgetState.rightArrow: ArrowState
Current state of right Carousel arrow
@public
rightArrow
.handleClick: () => voidhandleClick}
> next </React.JSX.IntrinsicElements.button: React.DetailedHTMLProps<React.ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>button> ); } }}
type ItemComponent: (props: {
    state: CarouselWidgetState;
    result?: Recommendation;
}) => React.ReactNode
A component rendering a single recommended item.
@public
ItemComponent
={(
props: {
    state: CarouselWidgetState;
    result?: Recommendation;
}
props
) => (
<
const DefaultItem: ((props: DefaultItemProps) => React.JSX.Element) & {
    displayName: string;
}
Default Item component provided for basic usage.
@public
DefaultItem
DefaultItemProps.href?: string | null | undefined
Item link URL.
@public
href
={function addRecommIdQueryParam(url: string, recommId: string | undefined): string
Utility function to append `recombee_recomm_id` parameter to an url string. For usage in widget template to construct item link URL.
@public
addRecommIdQueryParam
(
`${
props: {
    state: CarouselWidgetState;
    result?: Recommendation;
}
props
.result?: Recommendation | undefinedresult?.
values?: {
    [key: string]: any;
} | undefined
Item properties
@public
values
?.link}`,
props: {
    state: CarouselWidgetState;
    result?: Recommendation;
}
props
.state: CarouselWidgetStatestate.CarouselWidgetState.recommId: string | undefined
Id of recommendation response from which the items originated.
@public
recommId
,
)} DefaultItemProps.image?: React.ReactNode
Item Image element.
@public
image
={
<const ItemImage: React.FunctionComponent<ItemImageProps>
Item image component
@public
ItemImage
src?: string | null | undefined
Image URL
@public
src
={`${
props: {
    state: CarouselWidgetState;
    result?: Recommendation;
}
props
.result?: Recommendation | undefinedresult?.
values?: {
    [key: string]: any;
} | undefined
Item properties
@public
values
?.images?.[0]}`}
width?: number | undefined
Image width in pixels
@public
width
={600}
height?: number | undefined
Image height in pixels
@public
height
={400}
/> } DefaultItemProps.labelContent?: React.ReactNode
Item content above title. Sets the entire content of an item aside from an image.
@public
labelContent
={`${
props: {
    state: CarouselWidgetState;
    result?: Recommendation;
}
props
.result?: Recommendation | undefinedresult?.
values?: {
    [key: string]: any;
} | undefined
Item properties
@public
values
?.genres?.join(", ")}`}
DefaultItemProps.title?: React.ReactNode
Item title.
@public
title
={`${
props: {
    state: CarouselWidgetState;
    result?: Recommendation;
}
props
.result?: Recommendation | undefinedresult?.
values?: {
    [key: string]: any;
} | undefined
Item properties
@public
values
?.title}`}
DefaultItemProps.highlightedContent?: React.ReactNode
Item content under title. Sets the entire content of an item aside from an image.
@public
highlightedContent
={`${
props: {
    state: CarouselWidgetState;
    result?: Recommendation;
}
props
.result?: Recommendation | undefinedresult?.
values?: {
    [key: string]: any;
} | undefined
Item properties
@public
values
?.year}`}
/> )} /> ); };
Copy
import {
  const CarouselWidget: React.FunctionComponent<CarouselWidgetProps>
Carousel widget React Component. See {@link CarouselWidgetProps } for configuration options.
@public
CarouselWidget
,
const DefaultCarousel: ((props: DefaultCarouselProps) => React.JSX.Element) & {
    displayName: string;
}
Default visual component used to render carousel container
@public
DefaultCarousel
,
const ItemImage: React.FunctionComponent<ItemImageProps>
Item image component
@public
ItemImage
,
function clsx(...inputs: ClassValue[]): stringclsx, } from "@recombee/carousel-widget-react"; import "@recombee/carousel-widget-react/dist/styles.css"; export default () => ( <const CarouselWidget: React.FunctionComponent<CarouselWidgetProps>
Carousel widget React Component. See {@link CarouselWidgetProps } for configuration options.
@public
CarouselWidget
WidgetConfigurationBase<CreateRequestFunction>.apiClient: ApiClient
Instance of Recombee JS API Client. See {@link file://./#client-initialization Example } .
@public
apiClient
={const apiClient: ApiClientapiClient}
WidgetConfigurationBase<CreateRequestFunction>.createRequest: CreateRequestFunction
Request factory function. See {@link file://./#client-initialization Quick Example } or visit {@link file:///api API Reference } for overview of available requests.
@public
createRequest
={const createRequest: CreateRequestFunctioncreateRequest}
ArrowComponent?: ((props: CarouselArrowProps) => React.ReactNode) | undefined
A component rendering either left or right carousel arrow
@public
ArrowComponent
={() => null}
CarouselComponent?: ((props: DefaultCarouselProps) => React.ReactNode) | undefined
Component responsible for rendering the widget markup. Example in which the passed component wraps the default carousel component with additional custom HTML. ```tsx|-react import React from "react"; import { CarouselWidget, DefaultCarousel, } from "@recombee/carousel-widget-react"; //
@noErrors: 2739 <CarouselWidget // ...ommited code... CarouselComponent={(carouselProps) => { return ( <div> <h1>Recommended</h1> <DefaultCarousel {...carouselProps} /> </div> ); }} />; ``` ```ts|-js import React from "react"; import { CarouselWidget, DefaultCarousel, html, } from "@recombee/carousel-widget-js"; //@noErrors: 2345 CarouselWidget({ // ...ommited code... CarouselComponent: (carouselProps) => { return html` <div> <h1>Recommended</h1> <${DefaultCarousel} ...${carouselProps} /> </div> `; }, }); ``` This property also allows to fully cutomize the carousel HTML in extreme cases. ```tsx|-react import React from "react"; import { CarouselWidget } from "@recombee/carousel-widget-react"; //@noErrors: 2739 <CarouselWidget // ...ommited code... CarouselComponent={(carouselProps) => { return ( <div ref={carouselProps.state.wrapperRef.handle}> <h1>Recommended</h1> <div ref={carouselProps.state.contentRef.handle}> // Use carouselProps.state.items array to loop over items </div> </div> ); }} />; ``` ```ts|-js import React from "react"; import { CarouselWidget, html } from "@recombee/carousel-widget-js"; //@noErrors: 2345 CarouselWidget({ // ...ommited code... CarouselComponent: (carouselProps) => { return html` <div ref=${carouselProps.state.wrapperRef.handle}> <div ref=${carouselProps.state.contentRef.handle}> // Use carouselProps.state.items array to loop over items </div> </div> `; }, }); ```@public
CarouselComponent
={(props: DefaultCarouselProps<React.ReactNode>props) => (
<React.JSX.IntrinsicElements.div: React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>div React.HTMLAttributes<HTMLDivElement>.className?: string | undefinedclassName="p-4"> <
const DefaultCarousel: ((props: DefaultCarouselProps) => React.JSX.Element) & {
    displayName: string;
}
Default visual component used to render carousel container
@public
DefaultCarousel
{...props: DefaultCarouselProps<React.ReactNode>props} DefaultCarouselProps<React.ReactNode>.contentClassName?: string | undefined
Custom classes of content wrapper element. See {@link file://./#custom-css Custom CSS } .
@public
contentClassName
="gap-1"
DefaultCarouselProps<React.ReactNode>.itemWrapperClassName?: string | undefined
Custom classes of item wrapper element. See {@link file://./#custom-css Custom CSS } .
@public
itemWrapperClassName
="min-h-[240px] w-[200px]"
/> <React.JSX.IntrinsicElements.div: React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>div React.HTMLAttributes<HTMLDivElement>.className?: string | undefinedclassName="flex justify-end gap-2 pt-4"> <React.JSX.IntrinsicElements.div: React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>div React.HTMLAttributes<HTMLDivElement>.className?: string | undefinedclassName="flex gap-2"> <function CarouselButton(props: any): React.JSX.ElementCarouselButton disabled: booleandisabled={!props: DefaultCarouselProps<React.ReactNode>props.DefaultCarouselProps<React.ReactNode>.state: CarouselWidgetState
Carousel state.
@public
state
.CarouselWidgetState.leftArrow: ArrowState
Current state of left Carousel arrow
@public
leftArrow
.isVisible: booleanisVisible}
onClick: () => voidonClick={props: DefaultCarouselProps<React.ReactNode>props.DefaultCarouselProps<React.ReactNode>.state: CarouselWidgetState
Carousel state.
@public
state
.CarouselWidgetState.leftArrow: ArrowState
Current state of left Carousel arrow
@public
leftArrow
.handleClick: () => voidhandleClick}
> PREV </function CarouselButton(props: any): React.JSX.ElementCarouselButton> <function CarouselButton(props: any): React.JSX.ElementCarouselButton disabled: booleandisabled={!props: DefaultCarouselProps<React.ReactNode>props.DefaultCarouselProps<React.ReactNode>.state: CarouselWidgetState
Carousel state.
@public
state
.CarouselWidgetState.rightArrow: ArrowState
Current state of right Carousel arrow
@public
rightArrow
.isVisible: booleanisVisible}
onClick: () => voidonClick={props: DefaultCarouselProps<React.ReactNode>props.DefaultCarouselProps<React.ReactNode>.state: CarouselWidgetState
Carousel state.
@public
state
.CarouselWidgetState.rightArrow: ArrowState
Current state of right Carousel arrow
@public
rightArrow
.handleClick: () => voidhandleClick}
> NEXT </function CarouselButton(props: any): React.JSX.ElementCarouselButton> </React.JSX.IntrinsicElements.div: React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>div> </React.JSX.IntrinsicElements.div: React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>div> </React.JSX.IntrinsicElements.div: React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>div> )}
type ItemComponent: (props: {
    state: CarouselWidgetState;
    result?: Recommendation;
}) => React.ReactNode
A component rendering a single recommended item.
@public
ItemComponent
={(
props: {
    state: CarouselWidgetState;
    result?: Recommendation;
}
props
) => (
<React.JSX.IntrinsicElements.div: React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>div React.HTMLAttributes<HTMLDivElement>.className?: string | undefinedclassName="overflow-hidden rounded-lg border-[#ededed] bg-white text-[#282b30] dark:border-none dark:bg-transparent dark:text-white"> <React.JSX.IntrinsicElements.div: React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>div React.HTMLAttributes<HTMLDivElement>.className?: string | undefinedclassName="relative overflow-hidden bg-cover bg-no-repeat"> <const ItemImage: React.FunctionComponent<ItemImageProps>
Item image component
@public
ItemImage
src?: string | null | undefined
Image URL
@public
src
={`${
props: {
    state: CarouselWidgetState;
    result?: Recommendation;
}
props
.result?: Recommendation | undefinedresult?.
values?: {
    [key: string]: any;
} | undefined
Item properties
@public
values
?.images?.[0]}`}
width?: number | undefined
Image width in pixels
@public
width
={600}
height?: number | undefined
Image height in pixels
@public
height
={400}
/> {
props: {
    state: CarouselWidgetState;
    result?: Recommendation;
}
props
.result?: Recommendation | undefinedresult?.
values?: {
    [key: string]: any;
} | undefined
Item properties
@public
values
?.["genres"]?.includes("drama") && (
<React.JSX.IntrinsicElements.div: React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>div React.HTMLAttributes<HTMLDivElement>.className?: string | undefinedclassName="absolute top-3 left-3 bg-[#3f91ff] px-2 text-xs/[1.67] font-semibold text-white"> Drama </React.JSX.IntrinsicElements.div: React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>div> )} {
props: {
    state: CarouselWidgetState;
    result?: Recommendation;
}
props
.result?: Recommendation | undefinedresult?.
values?: {
    [key: string]: any;
} | undefined
Item properties
@public
values
?.["genres"]?.includes("science_fiction") && (
<React.JSX.IntrinsicElements.div: React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>div React.HTMLAttributes<HTMLDivElement>.className?: string | undefinedclassName="absolute top-3 left-3 bg-[#36c696] px-2 text-xs/[1.67] font-semibold text-white"> Sci-Fi </React.JSX.IntrinsicElements.div: React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>div> )} </React.JSX.IntrinsicElements.div: React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>div> <React.JSX.IntrinsicElements.div: React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>div React.HTMLAttributes<HTMLDivElement>.className?: string | undefinedclassName="p-3"> <React.JSX.IntrinsicElements.div: React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>div React.HTMLAttributes<HTMLDivElement>.className?: string | undefinedclassName="mb-1 line-clamp-4 overflow-hidden text-[14px]/[1.43] text-nowrap text-ellipsis text-[#80868f]"> {`${
props: {
    state: CarouselWidgetState;
    result?: Recommendation;
}
props
.result?: Recommendation | undefinedresult?.
values?: {
    [key: string]: any;
} | undefined
Item properties
@public
values
?.genres?.join(", ")}`}
</React.JSX.IntrinsicElements.div: React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>div> <React.JSX.IntrinsicElements.div: React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>div React.HTMLAttributes<HTMLDivElement>.className?: string | undefinedclassName="text-md mb-1 overflow-hidden text-nowrap text-ellipsis"> {`${
props: {
    state: CarouselWidgetState;
    result?: Recommendation;
}
props
.result?: Recommendation | undefinedresult?.
values?: {
    [key: string]: any;
} | undefined
Item properties
@public
values
?.title}`}
</React.JSX.IntrinsicElements.div: React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>div> <React.JSX.IntrinsicElements.div: React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>div React.HTMLAttributes<HTMLDivElement>.className?: string | undefinedclassName="line-clamp-4 pb-3 text-base text-[#3f91ff]"> {`${
props: {
    state: CarouselWidgetState;
    result?: Recommendation;
}
props
.result?: Recommendation | undefinedresult?.
values?: {
    [key: string]: any;
} | undefined
Item properties
@public
values
?.year}`}
</React.JSX.IntrinsicElements.div: React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>div> <React.JSX.IntrinsicElements.button: React.DetailedHTMLProps<React.ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>button React.HTMLAttributes<T>.className?: string | undefinedclassName="w-full rounded-lg border border-[#ededed] py-2 text-center text-[14px]/[1.43] font-medium text-[#80868f]"> Play </React.JSX.IntrinsicElements.button: React.DetailedHTMLProps<React.ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>button> </React.JSX.IntrinsicElements.div: React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>div> </React.JSX.IntrinsicElements.div: React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>div> )} /> ); function function CarouselButton(props: any): React.JSX.ElementCarouselButton(props: anyprops: any) { const const buttonClassName: "w-full rounded-lg border border-[#ededed] py-2 px-3 text-center text-[14px]/[1.43] font-medium text-[#80868f]"buttonClassName = `w-full rounded-lg border border-[#ededed] py-2 px-3 text-center text-[14px]/[1.43] font-medium text-[#80868f]`; return ( <React.JSX.IntrinsicElements.button: React.DetailedHTMLProps<React.ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>button React.HTMLAttributes<T>.className?: string | undefinedclassName={function clsx(...inputs: ClassValue[]): stringclsx(const buttonClassName: "w-full rounded-lg border border-[#ededed] py-2 px-3 text-center text-[14px]/[1.43] font-medium text-[#80868f]"buttonClassName, { "opacity-50": props: anyprops.disabled, })} {...props: anyprops} /> ); }
Copy

Some base styles are always applied to ensure the widget maintains the structural shape of a carousel.

However, these can be disabled or overridden if needed. Use the CarouselWidgetProps.classNameDisableDefault and related options to opt out of default styling.

import {
  const CarouselWidget: React.FunctionComponent<CarouselWidgetProps>
Carousel widget React Component. See {@link CarouselWidgetProps } for configuration options.
@public
CarouselWidget
,
const DefaultItem: ((props: DefaultItemProps) => React.JSX.Element) & {
    displayName: string;
}
Default Item component provided for basic usage.
@public
DefaultItem
,
const ItemImage: React.FunctionComponent<ItemImageProps>
Item image component
@public
ItemImage
,
function addRecommIdQueryParam(url: string, recommId: string | undefined): string
Utility function to append `recombee_recomm_id` parameter to an url string. For usage in widget template to construct item link URL.
@public
addRecommIdQueryParam
,
} from "@recombee/carousel-widget-react"; import "@recombee/carousel-widget-react/dist/styles.css"; export default () => { return ( <React.JSX.IntrinsicElements.div: React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>div React.HTMLAttributes<HTMLDivElement>.className?: string | undefinedclassName="flex justify-center"> <React.JSX.IntrinsicElements.div: React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>div React.HTMLAttributes<HTMLDivElement>.className?: string | undefinedclassName="w-[40%]"> <const CarouselWidget: React.FunctionComponent<CarouselWidgetProps>
Carousel widget React Component. See {@link CarouselWidgetProps } for configuration options.
@public
CarouselWidget
WidgetConfigurationBase<CreateRequestFunction>.apiClient: ApiClient
Instance of Recombee JS API Client. See {@link file://./#client-initialization Example } .
@public
apiClient
={const apiClient: ApiClientapiClient}
WidgetConfigurationBase<CreateRequestFunction>.createRequest: CreateRequestFunction
Request factory function. See {@link file://./#client-initialization Quick Example } or visit {@link file:///api API Reference } for overview of available requests.
@public
createRequest
={const createRequest: CreateRequestFunctioncreateRequest}
contentClassNameDisableDefault?: boolean | undefined
Disables default classes of content wrapper element. There are some default class names with essential styles applied to the content wrapper element. This setting disables them as an escape hatch for customization. See {@link file://./#custom-css Custom CSS } .
@public
contentClassNameDisableDefault
contentClassName?: string | undefined
Custom classes of content wrapper element. See {@link file://./#custom-css Custom CSS } .
@public
contentClassName
="rb:no-scrollbar flex min-h-[420px] snap-x snap-mandatory content-stretch gap-1 overflow-x-auto p-6"
itemWrapperClassNameDisableDefault?: boolean | undefined
Disables default classes of item wrapper element. There are some default class names with essential styles applied to the item wrapper element. This setting disables them as an escape hatch for customization. See {@link file://./#custom-css Custom CSS } .
@public
itemWrapperClassNameDisableDefault
itemWrapperClassName?: string | undefined
Custom classes of item wrapper element. See {@link file://./#custom-css Custom CSS } .
@public
itemWrapperClassName
="flex min-w-full flex-grow basis-full snap-center"
type ItemComponent: (props: {
    state: CarouselWidgetState;
    result?: Recommendation;
}) => React.ReactNode
A component rendering a single recommended item.
@public
ItemComponent
={(
props: {
    state: CarouselWidgetState;
    result?: Recommendation;
}
props
) => (
<
const DefaultItem: ((props: DefaultItemProps) => React.JSX.Element) & {
    displayName: string;
}
Default Item component provided for basic usage.
@public
DefaultItem
DefaultItemProps.href?: string | null | undefined
Item link URL.
@public
href
={function addRecommIdQueryParam(url: string, recommId: string | undefined): string
Utility function to append `recombee_recomm_id` parameter to an url string. For usage in widget template to construct item link URL.
@public
addRecommIdQueryParam
(
`${
props: {
    state: CarouselWidgetState;
    result?: Recommendation;
}
props
.result?: Recommendation | undefinedresult?.
values?: {
    [key: string]: any;
} | undefined
Item properties
@public
values
?.link}`,
props: {
    state: CarouselWidgetState;
    result?: Recommendation;
}
props
.state: CarouselWidgetStatestate.CarouselWidgetState.recommId: string | undefined
Id of recommendation response from which the items originated.
@public
recommId
,
)} DefaultItemProps.image?: React.ReactNode
Item Image element.
@public
image
={
<const ItemImage: React.FunctionComponent<ItemImageProps>
Item image component
@public
ItemImage
src?: string | null | undefined
Image URL
@public
src
={`${
props: {
    state: CarouselWidgetState;
    result?: Recommendation;
}
props
.result?: Recommendation | undefinedresult?.
values?: {
    [key: string]: any;
} | undefined
Item properties
@public
values
?.images?.[0]}`}
width?: number | undefined
Image width in pixels
@public
width
={600}
height?: number | undefined
Image height in pixels
@public
height
={400}
/> } DefaultItemProps.labelContent?: React.ReactNode
Item content above title. Sets the entire content of an item aside from an image.
@public
labelContent
={`${
props: {
    state: CarouselWidgetState;
    result?: Recommendation;
}
props
.result?: Recommendation | undefinedresult?.
values?: {
    [key: string]: any;
} | undefined
Item properties
@public
values
?.genres?.join(", ")}`}
DefaultItemProps.title?: React.ReactNode
Item title.
@public
title
={`${
props: {
    state: CarouselWidgetState;
    result?: Recommendation;
}
props
.result?: Recommendation | undefinedresult?.
values?: {
    [key: string]: any;
} | undefined
Item properties
@public
values
?.title}`}
DefaultItemProps.highlightedContent?: React.ReactNode
Item content under title. Sets the entire content of an item aside from an image.
@public
highlightedContent
={`${
props: {
    state: CarouselWidgetState;
    result?: Recommendation;
}
props
.result?: Recommendation | undefinedresult?.
values?: {
    [key: string]: any;
} | undefined
Item properties
@public
values
?.year}`}
/> )} /> </React.JSX.IntrinsicElements.div: React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>div> </React.JSX.IntrinsicElements.div: React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>div> ); };
Copy

API Reference

const

Carousel widget React Component. See CarouselWidgetProps for configuration options.

type

Carousel Widget React Component configuration properties

Properties

ApiClient

Instance of Recombee JS API Client. See Example.


CreateRequestFunction

Request factory function. See Quick Example or visit API Reference for overview of available requests.


WidgetRecommResponseCallback | undefined

Callback function allowing to intercept and inspect recommendation request+response made by widget.

Copy

string | undefined

A string key specifying a group of widgets, in which recommendation results will be deduplicated. By default, all widgets belong to a single group so all results from the same database are deduplicated.


number | undefined

Number of items to load immediately. Adjust to have more items loaded ahead of user scrolling.


string | undefined

Custom classes of widget wrapper element. See Custom CSS.


boolean | undefined

Disables default classes of widget wrapper element.

There are some default class names with essential styles applied to the widget wrapper element. This setting disables them as an escape hatch for customization. See Custom CSS.


string | undefined

Custom classes of content wrapper element. See Custom CSS.


boolean | undefined

Disables default classes of content wrapper element.

There are some default class names with essential styles applied to the content wrapper element. This setting disables them as an escape hatch for customization. See Custom CSS.


string | undefined

Custom classes of item wrapper element. See Custom CSS.


boolean | undefined

Disables default classes of item wrapper element.

There are some default class names with essential styles applied to the item wrapper element. This setting disables them as an escape hatch for customization. See Custom CSS.


(props: { state: CarouselWidgetState; result?: Recommendation | undefined; }) => ReactNode

A component rendering a single recommended item.


((props: CarouselArrowProps) => ReactNode) | undefined

A component rendering either left or right carousel arrow


((props: DefaultCarouselProps<ReactNode>) => ReactNode) | undefined

Component responsible for rendering the widget markup.

Example in which the passed component wraps the default carousel component with additional custom HTML.

import React from "react";
import {
  const CarouselWidget: React.FunctionComponent<CarouselWidgetProps>
Carousel widget React Component. See {@link CarouselWidgetProps } for configuration options.
@public
CarouselWidget
,
const DefaultCarousel: ((props: DefaultCarouselProps) => React.JSX.Element) & {
    displayName: string;
}
Default visual component used to render carousel container
@public
DefaultCarousel
,
} from "@recombee/carousel-widget-react"; <const CarouselWidget: React.FunctionComponent<CarouselWidgetProps>
Carousel widget React Component. See {@link CarouselWidgetProps } for configuration options.
@public
CarouselWidget
// ...ommited code... CarouselComponent?: ((props: DefaultCarouselProps) => React.ReactNode) | undefined
Component responsible for rendering the widget markup. Example in which the passed component wraps the default carousel component with additional custom HTML. ```tsx|-react import React from "react"; import { CarouselWidget, DefaultCarousel, } from "@recombee/carousel-widget-react"; //
@noErrors: 2739 <CarouselWidget // ...ommited code... CarouselComponent={(carouselProps) => { return ( <div> <h1>Recommended</h1> <DefaultCarousel {...carouselProps} /> </div> ); }} />; ``` ```ts|-js import React from "react"; import { CarouselWidget, DefaultCarousel, html, } from "@recombee/carousel-widget-js"; //@noErrors: 2345 CarouselWidget({ // ...ommited code... CarouselComponent: (carouselProps) => { return html` <div> <h1>Recommended</h1> <${DefaultCarousel} ...${carouselProps} /> </div> `; }, }); ``` This property also allows to fully cutomize the carousel HTML in extreme cases. ```tsx|-react import React from "react"; import { CarouselWidget } from "@recombee/carousel-widget-react"; //@noErrors: 2739 <CarouselWidget // ...ommited code... CarouselComponent={(carouselProps) => { return ( <div ref={carouselProps.state.wrapperRef.handle}> <h1>Recommended</h1> <div ref={carouselProps.state.contentRef.handle}> // Use carouselProps.state.items array to loop over items </div> </div> ); }} />; ``` ```ts|-js import React from "react"; import { CarouselWidget, html } from "@recombee/carousel-widget-js"; //@noErrors: 2345 CarouselWidget({ // ...ommited code... CarouselComponent: (carouselProps) => { return html` <div ref=${carouselProps.state.wrapperRef.handle}> <div ref=${carouselProps.state.contentRef.handle}> // Use carouselProps.state.items array to loop over items </div> </div> `; }, }); ```@public
CarouselComponent
={(carouselProps: DefaultCarouselProps<React.ReactNode>carouselProps) => {
return ( <React.JSX.IntrinsicElements.div: React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>div> <React.JSX.IntrinsicElements.h1: React.DetailedHTMLProps<React.HTMLAttributes<HTMLHeadingElement>, HTMLHeadingElement>h1>Recommended</React.JSX.IntrinsicElements.h1: React.DetailedHTMLProps<React.HTMLAttributes<HTMLHeadingElement>, HTMLHeadingElement>h1> <
const DefaultCarousel: ((props: DefaultCarouselProps) => React.JSX.Element) & {
    displayName: string;
}
Default visual component used to render carousel container
@public
DefaultCarousel
{...carouselProps: DefaultCarouselProps<React.ReactNode>carouselProps} />
</React.JSX.IntrinsicElements.div: React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>div> ); }} />;
Copy

This property also allows to fully cutomize the carousel HTML in extreme cases.

import React from "react";
import { const CarouselWidget: React.FunctionComponent<CarouselWidgetProps>
Carousel widget React Component. See {@link CarouselWidgetProps } for configuration options.
@public
CarouselWidget
} from "@recombee/carousel-widget-react";
<const CarouselWidget: React.FunctionComponent<CarouselWidgetProps>
Carousel widget React Component. See {@link CarouselWidgetProps } for configuration options.
@public
CarouselWidget
// ...ommited code... CarouselComponent?: ((props: DefaultCarouselProps) => React.ReactNode) | undefined
Component responsible for rendering the widget markup. Example in which the passed component wraps the default carousel component with additional custom HTML. ```tsx|-react import React from "react"; import { CarouselWidget, DefaultCarousel, } from "@recombee/carousel-widget-react"; //
@noErrors: 2739 <CarouselWidget // ...ommited code... CarouselComponent={(carouselProps) => { return ( <div> <h1>Recommended</h1> <DefaultCarousel {...carouselProps} /> </div> ); }} />; ``` ```ts|-js import React from "react"; import { CarouselWidget, DefaultCarousel, html, } from "@recombee/carousel-widget-js"; //@noErrors: 2345 CarouselWidget({ // ...ommited code... CarouselComponent: (carouselProps) => { return html` <div> <h1>Recommended</h1> <${DefaultCarousel} ...${carouselProps} /> </div> `; }, }); ``` This property also allows to fully cutomize the carousel HTML in extreme cases. ```tsx|-react import React from "react"; import { CarouselWidget } from "@recombee/carousel-widget-react"; //@noErrors: 2739 <CarouselWidget // ...ommited code... CarouselComponent={(carouselProps) => { return ( <div ref={carouselProps.state.wrapperRef.handle}> <h1>Recommended</h1> <div ref={carouselProps.state.contentRef.handle}> // Use carouselProps.state.items array to loop over items </div> </div> ); }} />; ``` ```ts|-js import React from "react"; import { CarouselWidget, html } from "@recombee/carousel-widget-js"; //@noErrors: 2345 CarouselWidget({ // ...ommited code... CarouselComponent: (carouselProps) => { return html` <div ref=${carouselProps.state.wrapperRef.handle}> <div ref=${carouselProps.state.contentRef.handle}> // Use carouselProps.state.items array to loop over items </div> </div> `; }, }); ```@public
CarouselComponent
={(carouselProps: DefaultCarouselProps<React.ReactNode>carouselProps) => {
return ( <React.JSX.IntrinsicElements.div: React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>div React.RefAttributes<HTMLDivElement>.ref?: React.Ref<HTMLDivElement> | undefined
Allows getting a ref to the component instance. Once the component unmounts, React will set `ref.current` to `null` (or call the ref with `null` if you passed a callback ref).
@see{@link https://react.dev/learn/referencing-values-with-refs#refs-and-the-dom React Docs}
ref
={carouselProps: DefaultCarouselProps<React.ReactNode>carouselProps.DefaultCarouselProps<React.ReactNode>.state: CarouselWidgetState
Carousel state.
@public
state
.CarouselWidgetState.wrapperRef: ObservableRef<HTMLElement>
React ref necessary to control the carousel wrapper element. See {@link CarouselWidgetProps.CarouselComponent Customization Example } .
wrapperRef
.ObservableRef<HTMLElement>.handle(element: HTMLElement | null): voidhandle}>
<React.JSX.IntrinsicElements.h1: React.DetailedHTMLProps<React.HTMLAttributes<HTMLHeadingElement>, HTMLHeadingElement>h1>Recommended</React.JSX.IntrinsicElements.h1: React.DetailedHTMLProps<React.HTMLAttributes<HTMLHeadingElement>, HTMLHeadingElement>h1> <React.JSX.IntrinsicElements.div: React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>div React.RefAttributes<HTMLDivElement>.ref?: React.Ref<HTMLDivElement> | undefined
Allows getting a ref to the component instance. Once the component unmounts, React will set `ref.current` to `null` (or call the ref with `null` if you passed a callback ref).
@see{@link https://react.dev/learn/referencing-values-with-refs#refs-and-the-dom React Docs}
ref
={carouselProps: DefaultCarouselProps<React.ReactNode>carouselProps.DefaultCarouselProps<React.ReactNode>.state: CarouselWidgetState
Carousel state.
@public
state
.CarouselWidgetState.contentRef: ObservableRef<HTMLElement>
React ref necessary to control the carousel content element. See {@link CarouselWidgetProps.CarouselComponent Customization Example } .
contentRef
.ObservableRef<HTMLElement>.handle(element: HTMLElement | null): voidhandle}>
// Use carouselProps.state.items array to loop over items </React.JSX.IntrinsicElements.div: React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>div> </React.JSX.IntrinsicElements.div: React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>div> ); }} />;
Copy

class

Exposes internal state data of the widget to be used in customizable components

Properties

ObservableRef<HTMLElement>

React ref necessary to control the carousel wrapper element. See CarouselWidgetProps.CarouselComponent.


ObservableRef<HTMLElement>

React ref necessary to control the carousel content element. See CarouselWidgetProps.CarouselComponent.


{ key: string; entity: Recommendation; }[]

Array of items to show in the carousel.


string | undefined

Id of recommendation response from which the items originated.


ArrowState

Current state of left Carousel arrow


ArrowState

Current state of right Carousel arrow


const

Default Item component provided for basic usage.

interface

Recommended item component properties.

Properties

string | undefined

Custom classes of item wrapper element. See Custom CSS.


boolean | undefined

Disables default classes of item wrapper element.

There are some default class names with essential styles applied to the item wrapper element. This setting disables them as an escape hatch for customization. See Custom CSS.


string | undefined

Custom classes of item image wrapper element. See Custom CSS.


boolean | undefined

Disables default classes of item image wrapper element.

There are some default class names with essential styles applied to the item image wrapper element. This setting disables them as an escape hatch for customization. See Custom CSS.


string | undefined

Custom classes of item content element. See Custom CSS.


Recommendation | undefined

A single item recommedation.


string | null | undefined

Item link URL.


ReactNode

Item Image element.


ReactNode

Item content above title. Sets the entire content of an item aside from an image.


string | undefined

Custom classes of label content wrapper element. See Custom CSS.


boolean | undefined

Disables default classes of label content wrapper element.

There are some default class names with essential styles applied to the label content wrapper element. This setting disables them as an escape hatch for customization. See Custom CSS.


ReactNode

Item title.


string | undefined

Custom classes of title wrapper element. See Custom CSS.


boolean | undefined

Disables default classes of title wrapper element.

There are some default class names with essential styles applied to the title wrapper element. This setting disables them as an escape hatch for customization. See Custom CSS.


ReactNode

Item content under title. Sets the entire content of an item aside from an image.


string | undefined

Custom classes of highlighted content wrapper element. See Custom CSS.


boolean | undefined

Disables default classes of highlighted content wrapper element.

There are some default class names with essential styles applied to the highlighted content wrapper element. This setting disables them as an escape hatch for customization. See Custom CSS.


ReactNode

Any custom content to display at the bottom of the item.


const

Item image component

type

Item Image properties

Properties

string | null | undefined

Image URL


string | undefined

URL of an image to display when the main image could not be loaded.


string | undefined

Image wrapper class name


string | undefined

Image class name


number | undefined

Image width in pixels


number | undefined

Image height in pixels


"top" | "center" | "bottom" | undefined

Image vertical alignment


"center" | "left" | "right" | undefined

Image horizontal alignment


"cover" | "scale_down" | undefined

Image fitting algorithm


type

Single recommendation item

Properties

string

Item ID


{ [key: string]: any; } | undefined

Item properties


function

Utility function to append recombee_recomm_id parameter to an url string. For usage in widget template to construct item link URL.

const

Default visual component used to render carousel container

interface

Carousel Properties

Properties

CarouselWidgetState

Carousel state.


string | undefined

Custom classes of widget wrapper element. See Custom CSS.


boolean | undefined

Disables default classes of widget wrapper element.

There are some default class names with essential styles applied to the widget wrapper element. This setting disables them as an escape hatch for customization. See Custom CSS.


string | undefined

Custom classes of content wrapper element. See Custom CSS.


boolean | undefined

Disables default classes of content wrapper element.

There are some default class names with essential styles applied to the content wrapper element. This setting disables them as an escape hatch for customization. See Custom CSS.


string | undefined

Custom classes of item wrapper element. See Custom CSS.


boolean | undefined

Disables default classes of item wrapper element.

There are some default class names with essential styles applied to the item wrapper element. This setting disables them as an escape hatch for customization. See Custom CSS.


(props: { state: CarouselWidgetState; result?: Recommendation | undefined; }) => ElementType

A component rendering a single recommended item.


((props: CarouselArrowProps) => ElementType) | undefined

A component rendering either left or right carousel arrow


const

Default Carousel arrow component

type

Carousel Arrow configuration options

Properties

"left" | "right"

The direction of an arrow to render.


CarouselWidgetState

Carousel state.


type

Factory for creating Recombee API Request to load data into a Widget.

type

CreateRequestFunction parameter

Properties

number

Number of items to fetch for the widget. Pass it to the appropriate Request constructor.


© Copyright 2025, Recombee s.r.o
docs.recombee.com