usePageConfig
Tells the Salla SDK which page the shopper is on by calling Salla.config.set('page', …) once, when the component mounts.
import { usePageConfig, PageConfigData } from '@salla.sa/twilight-theme-engine/hooks';In plain words
Salla's own scripts (the SDK, marketplace apps, analytics) like to know which page the shopper is looking at. Call usePageConfig({ slug: 'product.index', title: 'Chairs' }) in a page component, and the SDK is told once, when the page appears.
It does nothing on the server, and nothing visible: it only updates what Salla.config.get('page') returns.
Signature
function usePageConfig(pageData: PageConfigData): void
interface PageConfigData {
slug: string;
id?: string | number;
title: string;
url?: string; // default: the browser address bar's path + query string
parent?: { id: string | number; name: string; url: string } | null;
}Try it live
import { usePageConfig } from '@salla.sa/twilight-theme-engine/hooks';
export function PageHeading() {
// Runs once per mount. To report a different page, render the component with a new `key`.
usePageConfig({ slug: 'product.index', title: 'Chairs' });
return <h1>{'Chairs'}</h1>;
}
Example
import { usePageConfig } from '@salla.sa/twilight-theme-engine/hooks';
export function CategoryHeading({ category }: { category: { id: number; name: string } }) {
usePageConfig({ slug: 'product.index', id: category.id, title: category.name });
return <h1>{category.name}</h1>;
}
// Remount per category so the SDK hears about each one:
// <CategoryHeading key={category.id} category={category} />
How it behaves
Its effect has an empty dependency list: at mount it reads the latest
pageDatathrough a ref and callsSalla.config.set('page', { ...pageData, url }).Without
Salla.config.setit only warns in development, and never retries.The engine's own pages do not call it.
It has no subpath of its own: import it from
@salla.sa/twilight-theme-engine/hooks.
Gotchas
It runs once per mount. New props (the next category, when the same component stays mounted) do not update the SDK. Give the component a
keythat changes with the page.The default
urlis the browser address, not the router location. On localhost and the preview host that address includes the store segment. Passurlyourself when the SDK needs the router path.packages/theme-engine/docs/usePageConfig.md says the URL is detected from the router, that it is SSR compatible, and that it needs
TwilightProvider. The code readswindow.location, runs only in the browser, and needs no provider.