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).

app/components/HomeSections.tsx
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>;
}
app/routes/index.tsx
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

MethodParametersReturnsRequestLogin needed
home.blockshook: string, scope: { product_id } | { category_id } | { page_id }Promise<HomeComponentData[]>GET component/list?hooks={hook}&...No
home.componentsnonePromise<HomeComponentData[]>GET component/list, minus the blocks the merchant placed on product, category and custom pagesNo

Queries

QueryKey
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 HTTPError or TimeoutError.
  • ensureQueryData returns cached data without refetching, so a loader does not hit the network again until the data is stale or invalidated.

See also

On this page