Reading store data
Beginner10 min
Build a small store header one hook at a time with useStore, useTheme, useAsset and useTranslation.
Everything a header needs is already loaded before your component runs: the store's name and logo, the merchant's colors, the translations. You read it with hooks, one hook per kind of data.
Build a small store header below, one piece at a time. Each step adds one hook; the highlighted lines are what the step added.
1. The store name
useStore() returns the store this page belongs to. Its fields sit at the top level, so you take what you need straight out of it: here, name.
app/components/StoreHeader.tsx
import { useStore } from '@salla.sa/twilight-theme-engine/hooks/useStore';
export function StoreHeader() {
const { name } = useStore();
return (
<header className="store-header">
<strong>{name}</strong>
</header>
);
}
Which hook holds what
| Hook | Gives you | Import from |
|---|---|---|
useStore() | The store: name, logo, url, contacts, social, settings… | /hooks/useStore |
useTheme() | color, font, settings (your twilight.json settings) and isRTL | /hooks/useTheme |
useTranslation() | t, locale, direction, isRTL | /i18n |
useAsset() | URL builders: asset() for your theme's files, cdn() for Salla's asset CDN | /hooks/useAsset |
In engine terms
- The data comes from one request,
store/settings, made byrootBeforeLoadduring the server render and handed to the browser with the page.TwilightProviderkeeps itsstoreandthemein state;useStore()returns{ ...store, refresh }anduseTheme()returns{ color, font, settings, isRTL }(src/hooks/useStore.ts, src/hooks/useTheme.ts). refresh()re-reads the store fromSalla.config.all()in the browser; on the server, or before the SDK exists, it does nothing.tsearches Salla's shared messages first, then yourlocales/*.json.blocks.header.cartis one of Salla's.- All four hooks work in the server render, so this header is in the HTML a search engine reads.
- Reference: useStore, useTheme, useAsset, useTranslation, Link, and the Store and Theme types.