Search SDK
Troubleshooting and FAQs
Getting Started

Getting Started

Understanding the Basics

1. What's the difference between CSR and SSR approaches?

FeatureClient-Side Rendering (CSR)Server-Side Rendering (SSR)
Rendering LocationBrowser (Client)Server
Initial Load TimeSlower (JavaScript must load before content renders)Faster (HTML is fully rendered on server)
SEOLimited (content not immediately available to crawlers)Better (content is pre-rendered and crawler-friendly)
InteractivityFaster after initial load (SPA-like experience)Additional latency for interactions (requires hydration)
CachingLimited to static assetsComprehensive (entire pages can be cached on server)
Use CasesInteractive applications, real-time updates, single-page appsSEO-critical sites, e-commerce platforms, content-heavy pages

2. What features are available in the React Search SDK?

The Unbxd React Search SDK provides a comprehensive set of features for e-commerce development:

  • Search and Navigation: Build search bars, facets, and category navigation.
  • Pagination and Sorting: Implement pagination and sorting to enhance product discovery.
  • Customizable Product Display: Leverage hooks or components for tailored layouts.
  • Faceted Search: Allow users to filter products by attributes like color, size, or brand.
  • Banners and Promotions: Display dynamic, contextual banners and promotions.
  • Breadcrumb Navigation: Enable easy navigation through categories and filters.
  • Autosuggest: Provide real-time search suggestions as users type, improving search efficiency.
  • SEO-Optimized URLs: Create search-friendly URLs for better SEO.
  • Multi-Device Compatibility: Ensure consistent performance across desktops, tablets, and mobile devices.

3. Which approach should I choose for my project?

Choose CSR when you need:

  • Highly interactive user interfaces
  • Real-time search updates
  • Single-page application architecture
  • Client-side routing integration

Choose SSR when you prioritize:

  • Search engine optimization (SEO)
  • Fast initial page loads
  • Better Core Web Vitals scores
  • Search engine indexability
  • In your CSR or SSR approach, you can use both the @unbxd-ui/react-search-components and @unbxd-ui/react-search-hooks packages.
  • Use the @unbxd-ui/react-search-components package for pre-built components and the @unbxd-ui/react-search-hooks package for core functionality and wrappers.
  • If you choose to create your own components, you can use the hooks from the @unbxd-ui/react-search-hooks package.

Choose Custom Hooks when you want:

  • Complete UI customization
  • Integration with existing design systems
  • Custom state management
  • Headless implementation

Setup and Configuration

1. How do I get SiteKey and APIKey from Netcore Unbxd?

To obtain your siteKey and apiKey, please visit this configuration guide (opens in a new tab).

2. How do I install the React Search SDK?

Choose the installation method based on your preferred approach:

# Complete solution (components + hooks)
npm install @unbxd-ui/react-search-components @unbxd-ui/react-search-hooks
 
# Hooks-only (for custom UI implementation)
npm install @unbxd-ui/react-search-hooks
 
# Using Yarn
yarn add @unbxd-ui/react-search-components @unbxd-ui/react-search-hooks
 
# Using pnpm
pnpm add @unbxd-ui/react-search-components @unbxd-ui/react-search-hooks

3. What are the minimum version requirements?

Required dependencies:

  • React: 18.2.0 or higher
  • React DOM: 18.2.0 or higher
  • Node.js: 16.x or higher (18.x recommended)
  • TypeScript: 5.0 or higher (if using TypeScript)
  • Next.js: 14.0 or higher (for SSR implementations)
⚠️
Important Note:
Using React versions below 18.2.0 may cause incompatibilities with concurrent features and hooks.

4. Do I need both `react-search-components` and `react-search-hooks` packages?

Your package requirements depend on your implementation approach:

  1. Using Ready-Made Components

    • Install both packages:
    • @unbxd-ui/react-search-components: Pre-built UI components
    • @unbxd-ui/react-search-hooks: Core functionality and wrappers
  2. Custom Implementation

    • Install only @unbxd-ui/react-search-hooks
    • Build custom components using the provided hooks
  3. Hybrid Approach

    • Install both packages
    • Mix pre-built components with custom implementations

Example implementations:

// Client-Side Rendering (CSR)
// Using pre-built components
import { UnbxdSearchCSRWrapper } from "@unbxd-ui/react-search-hooks";
import { SearchBox, Products } from "@unbxd-ui/react-search-components";
 
// Custom implementation with hooks
import { UnbxdSearchCSRWrapper, useProducts, useQuery } from "@unbxd-ui/react-search-hooks";
// Server-Side Rendering (SSR)
// Using pre-built components
import { UnbxdSearchSSRWrapper } from "@unbxd-ui/react-search-hooks";
import { SearchBox, Products } from "@unbxd-ui/react-search-components";
 
// Custom implementation with hooks
import { UnbxdSearchSSRWrapper, useProducts, useQuery } from "@unbxd-ui/react-search-hooks";

5. What is UID and how do I generate it?

A UID (User ID) is a unique identifier for visitors that enables personalization, segmentation, and A/B testing of merchandising campaigns. The Unbxd Analytics JavaScript sets this ID in your browser cookie.

You can pass the UID using the headers object in the wrapper component for CSR or the initialize function for SSR:

// This is a sample code for above example. 
 
// CSR
<UnbxdSearchCSRWrapper apiUrlConfig={{ headers: { "unbxd-user-id": "your-uid" }}} >
	<SearchBox />
	<Products />
</UnbxdSearchCSRWrapper>
// This is a sample code for above example. 
 
// SSR
const initialData = await initialize({
	apiKey: "your-api-key",
	siteKey: "your-site-key",
	apiUrlConfig: {
		headers: { "unbxd-user-id": "your-uid" },
	}
	
});
 
<UnbxdSearchSSRWrapper initialData={initialData}>
	<SearchBox />
	<Products />
</UnbxdSearchSSRWrapper>

Implementation and Customization

1. Can I use my own components with the React Search SDK?

Yes, you can use your own components with the React Search SDK by utilizing hooks from the @unbxd-ui/react-search-hooks package. Custom components must be wrapped by the wrapper components provided by the package.

// This is a sample code for above example. 
import { UnbxdSearchCSRWrapper, useProducts, useQuery } from "@unbxd-ui/react-search-hooks";
 
const Products = () => {
	const { products } = useProducts();
	return (
		<div className="products-container">
			{products.map((product) => (
				<div key={product.id} className="product-card">
					<img src={product.image} alt={product.name} />
					<div className="product-name">{product.name}</div>
					<div className="product-price">{product.price}</div>
				</div>
			))}
		</div>
	);
};
 
const SearchBox = () => {
	const { query, setQuery } = useQuery({ delay: 0, forceReload: false });
	return <input type="text" placeholder="Search products..." className="search-box" value={query} onChange={(e) => setQuery(e.target.value)} />;
};
 
const App = () => {
	return (
		<UnbxdSearchCSRWrapper>
			<SearchBox />
			<Products />
		</UnbxdSearchCSRWrapper>
	);
};

2. Can I use this SDK with TypeScript?

Yes, the SDK includes comprehensive TypeScript support with type definitions:

// This is a sample code for above example. 
import { UnbxdSearchCSRWrapper } from "@unbxd-ui/react-search-hooks";
import { SearchBox, Products } from "@unbxd-ui/react-search-components";
 
// Type definitions for wrapper configuration
interface UnbxdSearchCSRWrapperProps {
	siteKey: string;
	apiKey: string;
	defaultValues?: {
		query?: string;
		pageSize?: number;
	};
	// Additional configuration options
}
 
// Type definitions for component props
interface SearchBoxProps {
	placeholder?: string;
	showSubmitButton?: boolean;
	// Additional component options
}
 
// Example implementation with TypeScript
const config: UnbxdSearchCSRWrapperProps = {
	apiKey: "your-api-key",
	siteKey: "your-site-key",
	defaultValues: {
		query: "*",
		pageSize: 20,
	},
};
 
const searchBoxProps: SearchBoxProps = {
	placeholder: "Search products...",
	showSubmitButton: true,
};

3. Can I add debounce to prevent multiple search API calls?

Yes, the SDK provides options to add debounce to the API calls:

Using the SearchBox component:

// Using the SearchBox component with debounce
<SearchBox debounce={true} delay={1000} />

Using the useQuery hook:

// Using the useQuery hook with delay
const { query, setQuery } = useQuery({
	delay: 1000,
});

4. How do I add custom headers to API requests?

You can add custom headers to API requests using the apiUrlConfig prop:

<UnbxdSearchCSRWrapper apiUrlConfig={{ headers: { "Unbxd-User-Id": "your-user-id" } }}>// Your components</UnbxdSearchCSRWrapper>

Troubleshooting and Performance

1. How do I resolve peer dependency warnings?

Follow these steps to resolve peer dependency warnings:

# 1. Check your current React version
npm list react
 
# 2. Install compatible versions
npm install react@18.2.0 react-dom@18.2.0
 
# 3. If needed, use legacy peer deps flag
npm install --legacy-peer-deps

For package.json configuration:

{
	"resolutions": {
		"react": "18.2.0",
		"react-dom": "18.2.0"
	}
}

2. How do I handle React version conflicts?

Follow this systematic approach:

  1. Identify current versions:
npm list react react-dom
  1. Update to compatible versions:
npm install react@^18.2.0 react-dom@^18.2.0
  1. Configure package.json overrides:
{
	"overrides": {
		"react": "^18.2.0",
		"react-dom": "^18.2.0"
	}
}
  1. For Yarn workspaces:
{
	"resolutions": {
		"react": "^18.2.0",
		"react-dom": "^18.2.0"
	}
}

3. How do I optimize bundle size?

Follow these optimization strategies:

  1. Use selective imports:
  • Components:

    // ❌ Avoid importing entire library
    import * as Components from "@unbxd-ui/react-search-components";
     
    // âś… Import only needed components
    import { SearchBox, Products } from "@unbxd-ui/react-search-components";
  • CSS Styles:

    // ❌ Avoid importing entire styles
    import "@unbxd-ui/react-search-components/styles/index.css";
     
    // âś… Import only needed styles
    import "@unbxd-ui/react-search-components/styles/searchbox.css";
  1. Implement code splitting:
// This is a sample code for above example. 
 
// âś… Lazy load components
const Facets = lazy(() =>
	import("@unbxd-ui/react-search-components").then((module) => ({
		default: module.Facets,
	}))
);
 
function SearchPage() {
	const [showFacets, setShowFacets] = useState(false);
 
	return (
		<div>
			<SearchBox />
			<Products />
			{showFacets && (
				<Suspense fallback={<div>Loading filters...</div>}>
					<Facets />
				</Suspense>
			)}
		</div>
	);
}
  1. Analyze bundle composition:
# Install and run bundle analyzer
npm install --save-dev webpack-bundle-analyzer
npx webpack-bundle-analyzer build/static/js/*.js
  1. Enable tree shaking:
// webpack.config.js
module.exports = {
	optimization: {
		usedExports: true,
		sideEffects: false,
	},
};

Common Issues and Solutions

1. What happens if API keys are invalid?

If you provide invalid apiKey or siteKey values, API calls will fail and components will render their fallback UI. Always ensure you're using valid credentials from your Unbxd dashboard.

2. Why aren't my search results displaying?

Follow this troubleshooting checklist:

  1. Verify imports: Ensure that you have imported the components and wrapper correctly.
// Ensure correct imports
import { UnbxdSearchCSRWrapper } from "@unbxd-ui/react-search-hooks";
import { SearchBox, Products } from "@unbxd-ui/react-search-components";
  1. Check wrapper configuration: Check if all the props given to the wrapper are correct.
// Verify API credentials and configuration
const SearchImplementation = () => (
	<UnbxdSearchCSRWrapper
		apiKey="your-valid-api-key"
		siteKey="your-valid-site-key"
		defaultValues={{
			query: "*", // Default search query
		}}>
		<SearchBox />
		<Products />
	</UnbxdSearchCSRWrapper>
);
  1. Monitor events: The onEvent function receives multiple events. You can use the type property to identify the event and handle it accordingly. Click here to see the list of events.
// Add event monitoring
const onEvent = (event, message, value, state) => {
    console.log({
        event,
        message,
        value,
        state
    });
};
 
<UnbxdSearchCSRWrapper
    onEvent={onEvent}
    // ... other props
>

3. Why am I getting "Cannot read property" errors?

These errors typically occur in three scenarios:

  1. Missing Wrapper Component:
// ❌ Wrong: Using components without wrapper
function SearchPage() {
	return <SearchBox />; // Will cause "Cannot read property" errors
}
 
// âś… Correct: Wrap with wrapper component
function SearchPage() {
	return (
		<UnbxdSearchCSRWrapper siteKey="YOUR_SITE_KEY" apiKey="YOUR_API_KEY">
			<SearchBox />
		</UnbxdSearchCSRWrapper>
	);
}
  1. Accessing Data Before It's Available:
// ❌ Wrong: Not checking for undefined
function ProductList() {
	const { products } = useProducts();
	return products.map((product) => <Product {...product} />);
}
 
// âś… Correct: Add null checks
function ProductList() {
	const { products = [] } = useProducts();
	return products?.map((product) => <Product {...product} />);
}
  1. SSR Data Hydration:
// âś… Correct: Provide initial data for SSR
export default function Page({ initialData }) {
	return (
		<UnbxdSearchSSRWrapper initialData={initialData}> // Prevents hydration errors
			<SearchResults />
		</UnbxdSearchSSRWrapper>
	);
}

4. How do I handle network failures gracefully?

Listen to the API_ERROR event to handle network failures:

const onEvent = (type, message, value, state) => {
	if (type === "API_ERROR") {
		// show fallback UI
	}
};
 
<UnbxdSearchCSRWrapper onEvent={onEvent}>// Your components</UnbxdSearchCSRWrapper>;

5. How do I debug state update issues?

The SDK fires different events for various user actions. Monitor these events using the onEvent prop to debug state updates. If expected events aren't firing, check your component hierarchy and code for errors. See the events documentation (opens in a new tab) for a complete list.

6. Why are components not re-rendering?

Components should re-render on state changes triggered by user actions. If a component isn't re-rendering:

  1. Check if the corresponding event is firing using the onEvent prop
  2. Verify the component is properly wrapped in the UnbxdSearch wrapper
  3. Ensure all required props and configurations are correctly set
  4. Check for any React key prop issues in lists or dynamic content