Getting Started
Pre-Setup Requirements
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. What's the difference between CSR and SSR approaches?
Feature | Client-Side Rendering (CSR) | Server-Side Rendering (SSR) |
---|---|---|
Rendering Location | Browser (Client) | Server |
Initial Load Time | Slower (JavaScript must load before content renders) | Faster (HTML is fully rendered on server) |
SEO | Limited (content not immediately available to crawlers) | Better (content is pre-rendered and crawler-friendly) |
Interactivity | Faster after initial load (SPA-like experience) | Additional latency for interactions (requires hydration) |
Caching | Limited to static assets | Comprehensive (entire pages can be cached on server) |
Use Cases | Interactive applications, real-time updates, single-page apps | SEO-critical sites, e-commerce platforms, content-heavy pages |
3. 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.
4. 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 make use of both the
@unbxd-ui/react-search-components
and@unbxd-ui/react-search-hooks
packages. - You can use the@unbxd-ui/react-search-components
package to get the pre-built components and the@unbxd-ui/react-search-hooks
package to get the core functionality and wrappers. - But if you choose to create your own components, you can use the hooks from the@unbxd-ui/react-search-hooks
package to get the core functionality and wrappers.
Choose Custom Hooks when you want:
- Complete UI customization
- Integration with existing design systems
- Custom state management
- Headless implementation
5. Can I use my own components with the React Search SDK?
Yes, you can use your own components with the React Search SDK. You can use the hooks from the @unbxd-ui/react-search-hooks
package to get the core functionality and wrappers.
You can create custom components by making use of the respective hooks. But you need to be sure that these custom components need to wrapper by the wrapper components provided by the @unbxd-ui/react-search-hooks
package.
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>
);
};
6. What is UID? How do I generate it?
UID is a unique identification for the visitors. It helps in personalisation, segmentation and A/B testing of merchandising campaigns will not work. The Unbxd Analytics javascript sets the userid in your browser cookie.
You can pass the UID by making use of the headers
object that is passed to the wrapper component in the case of CSR or to the initialize function in the case of SSR.
// CSR
<UnbxdSearchCSRWrapper headers={{ "unbxd-user-id": "your-uid" }}>
<SearchBox />
<Products />
</UnbxdSearchCSRWrapper>
// SSR
Basic Setup Questions
1. 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
2. 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)
3. Do I need both `react-search-components` and `react-search-hooks` packages?
Your package requirements depend on your implementation approach:
-
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
-
Custom Implementation
- Install only
@unbxd-ui/react-search-hooks
- Build custom components using the provided hooks
- Install only
-
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";
4. Can I use this SDK with TypeScript?
Yes, the SDK includes comprehensive TypeScript support with type definitions:
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,
};
Troubleshooting and Post-Setup
1. How do I resolve peer dependency warnings?
If you encounter peer dependency warnings, follow these steps:
# 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 to resolve version conflicts:
- Identify current versions:
npm list react react-dom
- Update to compatible versions:
npm install react@^18.2.0 react-dom@^18.2.0
- Configure package.json overrides:
{
"overrides": {
"react": "^18.2.0",
"react-dom": "^18.2.0"
}
}
- For Yarn workspaces:
{
"resolutions": {
"react": "^18.2.0",
"react-dom": "^18.2.0"
}
}
3. How do I optimize bundle size?
Follow these optimization strategies:
- Use selective imports:
// ❌ 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";
- Implement code splitting:
// âś… 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>
);
}
- Analyze bundle composition:
# Install and run bundle analyzer
npm install --save-dev webpack-bundle-analyzer
npx webpack-bundle-analyzer build/static/js/*.js
- Enable tree shaking:
// webpack.config.js
module.exports = {
optimization: {
usedExports: true,
sideEffects: false,
},
};
4. Why aren't my search results displaying?
Follow this troubleshooting checklist:
- Verify imports:
// Ensure correct imports
import { UnbxdSearchCSRWrapper } from "@unbxd-ui/react-search-hooks";
import { SearchBox, Products } from "@unbxd-ui/react-search-components";
- Check wrapper configuration:
// 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>
);
- Monitor events:
// Add event monitoring
const onEvent = (event, message, value, state) => {
console.log({
event,
message,
value,
state
});
};
<UnbxdSearchCSRWrapper
onEvent={onEvent}
// ... other props
>
- Component hierarchy:
// ❌ Incorrect placement
function App() {
return (
<div>
<SearchBox /> {/* Won't work outside wrapper */}
<UnbxdSearchCSRWrapper>
<Products />
</UnbxdSearchCSRWrapper>
</div>
);
}
// âś… Correct placement
function App() {
return (
<UnbxdSearchCSRWrapper>
<SearchBox />
<Products />
</UnbxdSearchCSRWrapper>
);
}