useUtilities
Overview
The useUtilities hook provides utility functions for managing search state and triggering refreshes. It offers a simple way to manually refresh search results by toggling the refresh state, which forces the search API to re-fetch data with the current query, filters, and other search parameters.
⚠️
Note:
The useUtilities hook must be used within the wrapper (in CSR, SSR and Custom Hooks approaches) to ensure that the respective component(s) and the search functionality work properly.
Usage
import { useUtilities } from "@unbxd-ui/react-search-hooks";Code Example
import { useUtilities } from "@unbxd-ui/react-search-hooks";
const RefreshButton = () => {
const { refresh } = useUtilities();
const handleRefresh = () => {
refresh();
};
return (
<button onClick={handleRefresh}>
Refresh Results
</button>
);
};Hook API
Return Values
A function that manually triggers a refresh of the search results. When called, it toggles the refresh state, which causes the search API to re-fetch data with the current search parameters (query, filters, pagination, sorting, etc.).
Usage:
const { refresh } = useUtilities();
// Trigger a refresh
refresh();Behavior:
- Toggles the refresh state in the store
- Forces the search API to re-execute with current parameters
- Useful for refreshing results after external updates or user actions
- Does not modify any search parameters (query, filters, etc.)
Important Notes
- The
refreshfunction does not change any search parameters - it only triggers a re-fetch with the current state - Each call to
refresh()toggles the refresh state, so multiple consecutive calls will still work - The refresh happens automatically when the state changes - no need to manually call API functions
- This hook is particularly useful when you need to refresh results without changing the search query or filters