1. Search API

Search hooks for React and Next.js

Version:

Sitecore's @sitecore-content-sdk/react and @sitecore-content-sdk/nextjs packages provide hooks to execute search queries with pagination, infinite scrolling, and typeahead suggestions. The hooks available are:

  • useSearch - use for pagination with page numbers
  • useInfiniteSearch - use for infinite scrolling with load more functionality
  • useSuggest - use for typeahead suggestions and preview results as a user types

useSearch and useInfiniteSearch also support More Like This (MLT) queries via seedItemId and seedItemUrl.

All three hooks support generic types for type-safe results and are automatically integrated to SitecoreAI via the SitecoreProvider.

Prerequisites

Before using these hooks, ensure that your application is wrapped using the SitecoreProvider. This allows the hooks to access required configuration from the SitecoreProvider context.

import { SitecoreProvider } from '@sitecore-content-sdk/nextjs';

function App() {
  return (
    <SitecoreProvider>
      {/* Your app components */}
    </SitecoreProvider>
  );
}
If you have suggestions for improving this article, let us know!