home
Fetch the list of home page components that the store merchant arranged.
Use home to learn which sections the merchant placed on the home page, and in what order. Your theme then renders each entry (see Add a home block).
import { useQuery } from '@tanstack/react-query';
import { home } from '@salla.sa/twilight-theme-engine/api/home';
export function HomeSections() {
const { data: components = [] } = useQuery(home.queries.components());
return <p>{components.length} sections</p>;
}import { home } from '@salla.sa/twilight-theme-engine/api/home';
import { getTwilightContext } from '@salla.sa/twilight-theme-engine/tanstack';
loader: async () => {
const { queryClient } = getTwilightContext();
return queryClient.ensureQueryData(home.queries.components());
},Methods
| Method | Parameters | Returns | Request | Login needed |
|---|---|---|---|---|
home.blocks | hook: string, scope: { product_id } | { category_id } | { page_id } | Promise<HomeComponentData[]> | GET component/list?hooks={hook}&... | No |
home.components | none | Promise<HomeComponentData[]> | GET component/list, minus the blocks the merchant placed on product, category and custom pages | No |
Queries
| Query | Key |
|---|---|
queries.components() | ['home', 'components', { scope }] |
The key includes the active scope, because each market has its own home page. It does not include the locale, so add it to your own key if your home page changes language without a reload.
Gotchas
- Returns
[]when the response has no data. - A failed request throws
HTTPErrororTimeoutError. ensureQueryDatareturns cached data without refetching, so a loader does not hit the network again until the data is stale or invalidated.