React SDK

useSearchContext

useSearchContext will return the data from the current search. The benefit of using this hook rather than the useSearch hook, is that it is side effect free, meaning calling useSearchContext will not perform a new search.

Usage

Additional imports used in the examples:

Editable Example
{
  "empty": false,
  "page": 1,
  "pageCount": 0,
  "resultsPerPage": 15,
  "searched": false,
  "searching": false,
  "totalResults": 0
}

Anatomy

useSearchContext returns an object containing the following properties:

NameTypeDefaultDescription
emptybooleanIf the response was empty, indicating an issue with the request.
errorError | nullThe error encountered while searching.
latencynumberThe engine latency.
pagenumberThe current page.
pageCountnumberThe total number of pages.
queryValuesMap<string, string>The query values from the response.
resultsResult[]An array of results that met the query.
resultsPerPagenumberThe number of results returned per page.
searchedbooleanIf an initial search has been performed.
searchingbooleanIs a search request being processed.
totalResultsnumberThe total count of results.

Parameters

NameTypeDefaultDescription