Documentation
useCategory

useCategory

Overview

The useCategory hook in the SDK is designed to manage and update the selected category state. It provides a streamlined interface for accessing the current category path and updating it dynamically based on user interactions.

Usage

import { useCategory } from "@unbxd-ui/react-search-hooks";
⚠️
Note:

The useCategory 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.

Code Example

import { useCategory } from "@unbxd-ui/react-search-hooks";
 
const SummaryComponent = () => {
	const { path, setCategory } = useCategory({ forceReload: false });
 
	const handleCategoryClick = () => {
		setCategory(`categoryPath:"Dresses"`)
	};
 
	return <div className="summary-wrapper">
        <div className="summary-text">
            Showing results for <b>'{path}'</b>
        </div>
        <div>
            Do you want to view products for <span><b>'Dresses'</b></span>?
        </div>
    </div>
};

Hook API

Parameters

forceReload

boolean
  • Turn this boolean to true if you want the api call to trigger even when you hit the same query. If this is turned to false, then for the same query, multiple calls will not happen.
  • Default Value: false.

Return Values

path

string
  • This value the current category path for which the products are being shown.

setCategory

function
  • This function allows users to set a new category path by passing the desired path as a parameter. It updates the current browse state, enabling real-time adjustments based on user input or interactions.

Use Cases