Search hooks for React and Next.js
Sitecore's @sitecore-content-sdk/react and @sitecore-content-sdk/nextjs packages provide hooks to execute search queries with pagination and infinite scrolling. The two hooks available are:
-
useSearch- use for pagination with page numbers -
useInfiniteSearch- use for infinite scrolling with load more functionality
Both hooks support generic types for type-safe results, sorting, custom page sizes, and queries. They're 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.
RequestResponse
import { SitecoreProvider } from '@sitecore-content-sdk/nextjs';
function App() {
return (
<SitecoreProvider>
{/* Your app components */}
</SitecoreProvider>
);
}