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 numbersuseInfiniteSearch- use for infinite scrolling with load more functionalityuseSuggest- 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.
If you have suggestions for improving this article, let us know!