useStore
Reads the current store (name, logo, settings, contacts…) and can refresh it from the Salla SDK.
import { useStore, UseStoreResult } from '@salla.sa/twilight-theme-engine/hooks/useStore';In plain words
Every page is rendered for one store. useStore() hands your component that store as a plain object: its name, logo, link, social accounts and store-wide settings.
It reads what the engine already loaded for the page, so calling it is instant and makes no request. Call it at the top of a component, like any hook.
Signature
function useStore(): UseStoreResult
interface UseStoreResult extends Store {
refresh: () => Promise<void>;
}Try it live
useStore(): {…} 24 keys
import { useStore } from '@salla.sa/twilight-theme-engine/hooks/useStore';
export function StoreBadge() {
// The store's fields are spread at the top level: there is no `store` key.
const { name, logo } = useStore();
return (
<span className="store-badge">
<img src={logo} alt="" width={24} height={24} />
{name}
</span>
);
}
Example
import { useStore } from '@salla.sa/twilight-theme-engine/hooks/useStore';
export function StoreBadge() {
const { name, logo } = useStore();
return (
<span className="store-badge">
<img src={logo} alt="" width={24} height={24} />
{name}
</span>
);
}
How it behaves
The store fields are spread onto the result, so destructure them directly:
const { name, logo } = useStore(). There is nostorekey.refresh()readsSalla.config.all()and merges itsstoreinto the provider state. It does nothing until the Salla SDK exists (it isundefinedduring the server render).It is
useTwilight().storeplusrefresh, so it throws outsideTwilightProvider.
Gotchas
docs/18-hooks-api.md shows
const { store, refresh } = useStore(). Thatstoreisundefined: the fields are spread at the top level of the result.
Related
Source and docs
- Engine source:
packages/theme-engine/src/hooks/useStore.ts