1. JS SDK reference

Query hooks

UI components communicate with Sitecore Search API using query hooks available in the JS SDK package. This topic describes the query hook pattern with a request and a query result, and then lists the various query hooks available in the JS SDK.

Request

To populate and render merchandising widgets, you must use React hooks to attach the components to the ReactQuery singleton in WidgetProvider.

The SDK provides a query hook for each type of merchandising widget. The following tables describe a typical query hook in the SDK:

KeyTypeDescription
queryobjectQuery function to be used. You can set additional request values to narrrow results.
widgetRefobjectReference the React component receiving data.
actionsobjectActions or callbacks used by the widget to populate request. Each widget type has its own list.
stateobjectParameters describing the state of the widget to be used by the search algorithm.
queryResultobjectContains the response object. A widget can only read its value.

Query result

queryResult is populated only while a query is running or after it has run. It contains various status values and the response.

KeyTypeDescription
isLoadingbooleanIf true, the query has no data and is currently fetching.
isErrorbooleanIf true, the query encountered an error.
isSuccessbooleanIf true, the query was successful and response object is available.
isFetchingbooleanIf true, the query is fetching, includes fetching in the background.
dataobjectResponse object.

Available query hooks

You can use the following query hooks in your application:

The JS SDK also includes secondary query hooks to support widgets, for example, list of widgets and breadcrumbs.

Notice

These React resources can help you with your implementation:

If you have suggestions for improving this article, let us know!