Query hooks

UI components communicate with Sitecore Discover 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:

Key

Type

Description

actions

object

Actions or callbacks used by the widget to populate request. Each widget type has its own list.

context

object

Request parameters populated by widget. Each widget type has its own list.

queryResult

object

Contains 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.

Key

Type

Description

isLoading

boolean

If true, the query has no data and is currently fetching.

isError

boolean

If true, the query encountered an error.

isSuccess

boolean

If true, the query was successful and response object is available.

isFetching

boolean

If true, the query is fetching, includes fetching in the background.

data

object

Response 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.

Do you have some feedback for us?

If you have suggestions for improving this article,