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:
Name | Type | Default | Description |
---|---|---|---|
empty | boolean | If the response was empty, indicating an issue with the request. | |
error | Error | null | The error encountered while searching. | |
latency | number | The engine latency. | |
page | number | The current page. | |
pageCount | number | The total number of pages. | |
queryValues | Map<string, string> | The query values from the response. | |
results | Result[] | An array of results that met the query. | |
resultsPerPage | number | The number of results returned per page. | |
searched | boolean | If an initial search has been performed. | |
searching | boolean | Is a search request being processed. | |
totalResults | number | The total count of results. | |
resetFilters | (emitEvent?: boolean) => void | Reset all filters to its default value and optionally emit their events. |
Parameters
Name | Type | Default | Description |
---|