GuidesAPI Reference
Home

React SDK

Learn about the Depict Search UI React SDK, its components and configuration.

The Depict UI React SDK enables seamless integration of Depict Search UI into your React web applications. With our developer-friendly components and wrappers, you can effortlessly add powerful search functionality to your eCommerce website.

The Depict search modal

The Depict search modal is the component that captures users' queries in a text field. This component is triggered when either of the following events occurs:

  • The open callback function, returned by the useDepictSearchModal hook, is called.
  • When a click event occurs on the DepictSearchField component.
    In both cases, you can align the top of the modal to the top of another DOM element by using the alignerRef property.

📘

Modal alignment on smaller screens

When the viewport height is below 900px, the search modal will overlook the element reference passed to the alignerRef property and center the search modal to the top of the viewport.

React component API

The SDK is pre-built with React components and wrappers, making it a perfect fit for React.js and Next.js web applications. The following sections describe these components and their configuration.

The DepictProvider component

The DepictProvider is a wrapper component for the root component of your entire application. It provides configuration to all Depict UI components beneath it

 return (
   <DepictProvider
     merchant="MERCHANT_ID"
     market="MARKET_IDENTIFIER"
     search={{
       searchPagePath: "SEARCH_RESULTS_PAGE_PATH",
     }}
   >
    <div className="App">
     ...
    </div>
   </DepictProvider>
);

The following table shows all DepictProvider configuration properties, their types, and descriptions:

PropsTypeDefaultDescription
merchantstringThis is the unique merchant identifier given by Depict.
marketstringThis specifies the market identifier.
searchobjectConfiguration object lets you customize your website's search parameters.
localeobjectenThis handles the Depict Search UI translations and price formatting, gotten from the Depict locale object.
navigateFunctionfunction
(href: string) => void
This function will be used internally by our components to navigate between Depict Search UI pages.
This prop is required in all applications that don’t use Next.JS
userIdstringIdentifies a logged in user, if applicable
metaDataobjectA <string, string> map of custom metadata to include in API requests to Depict

The search property on the DepictProvider wrapper is a configuration object that allows you to modify search parameters on your website. Use the config to tailor your search URL and behavior. The following table shows the search object's configuration properties:

PropsTypeDefaultDescription
searchPagePath stringundefinedThe unique URL path to your website's search page.
urlParamName stringsearch_queryThe URL parameter (or query string) for each search on your website.
enableCategorySuggestions booleanfalseTo enable or disable category suggestions.

The useSearchField hook

Use the useSearchField hook to render a search field on your site. The destructured value is the SearchField component to be nested within your application.
The SearchField component displays a search field that opens the Depict search modal.

SearchField with the modal aligned to the search field

import React from "react";
import { useSearchField } from "@depict-ai/react-ui";

const App = () => {
  const { SearchField } = useSearchField();

  return (
    <div>
      <SearchField />
    </div>
  );
};

SearchField with the modal aligned to another DOM element

import React from "react";
import { ComponentAligner, useSearchField } from "@depict-ai/react-ui";

const App = () => {
  const ref = useRef(null);
  const { SearchField } = useSearchField({
    alignerRef: ref
  });

  return (
    <div>
      <ComponentAligner ref={ref} />
      <SearchField />
    </div>
  );
};

The following table shows the useSearchField hook's configuration properties, their types, and descriptions:

PropTypeDefaultDescription
alignerRefReact.RefObjectundefinedThis is the ref of the element in the DOM to which you intend to align the resulting modal.

When not provided, the modal aligns on the SearchField itself.

The useSearchModal hook

Use the useSearchModal hook in place of the SearchField component to dynamically open the search modal.

const { open } = useSearchModal({
  location: "centered",
});

The destructured value is a function that opens the modal in response to user events. For example:

return (
 <div>
   <button onClick={open}>Search</button>
 </div>
);

The following table shows the useSearchModal hook's configuration properties, their types, and descriptions:

PropTypeDefaultDescription
location"centered" | "aligned""centered"This represents the location on the DOM to which the modal should be aligned. Set this value to aligned to align the modal to an element on your website.
alignerRefReact.RefObjectThis is the ref of the element in the DOM to which you intend to align the modal.

The SearchPage component

The SearchPage component acts as the search results page on your site. It is responsible for rendering results from each search.

import SearchProductCard from './SearchProductCard.js';

export default function SearchResultsPage() {

 return (
  <SearchPage
    productCard={SearchProductCard}
    columnsAtSize={[[1, 500], [2, 1000], [3]]}
  />
 );
}

The following table shows all SearchPage configuration properties, their types, and descriptions:

PropsTypeDefaultDescription
productCardReact.Element<typeof Component>The React component to use for rendering products.
columnsAtSizearray[[2,901],[3,1024],[4]]Used to customize breakpoints on the search results page. Handles the number of product card columns displayed at each screen size.
gridSpacing string | { horizontal: string; vertical: string }2%The spacing between products.
includeInputFieldbooleantrueSearch input field visibility.

The ImagePlaceholder component

This component renders a lightweight placeholder while your product data loads. Modify this component to replicate the dimensions of your actual product card.

if (!productData) {
    return <ImagePlaceholder aspectRatio={3 / 4} />
 }

The following table shows the ImagePlaceholder configuration properties, their types, and descriptions:

PropsTypeDefaultDescription
aspectRationumbernullThis property represents the aspect ratio of the image or product card to be displayed.

The TextPlaceholder component

This component renders a lightweight placeholder while your product data loads. Modify this component to replicate the dimensions of your actual product text data.

if (!productData) {
    return <TextPlaceholder width="30rem" height="17px" />
 }

The following table shows the TextPlaceholder configuration properties, their types, and descriptions:

PropsTypeDefaultDescription
widthstringnullThis property represents the width of the text to be displayed.
heightstringnullThis property defines the height of the text to be displayed.