Skip to content
Twilight React Playground
ثيم رائدaren

Core & providers

../providers./contexts

The provider every theme mounts once, the context it shares, and the component registry.

Every theme wraps its pages in one component, TwilightProvider. Everything else in the engine reads from it: the store, the theme settings, the language. This group is that foundation, plus the registry that lets a theme swap a built-in component for its own.

Entries

TwilightProvider

The component a theme mounts once around its pages; it shares the store, theme, language and navigation with everything inside it.

providerBeginnerlive demo
useTwilight

Reads everything TwilightProvider knows: store, theme, settings, language, direction, current page, login token and the Salla SDK.

hookBeginnerlive demo
useNavigate

Returns a navigate(path) function that moves to another store page from code, without reloading the whole page.

hookBeginnerlive demo
useLocation

Reads the current address as the router sees it (path, parsed query, raw query, hash), in the server render and in the browser.

hookBeginnerlive demo
useIsHome, useIsProduct…

Seven yes-or-no hooks that tell a component which kind of store page is showing: home, product, cart, account, blog, brands or search.

hookBeginnerlive demo
useRouteId

Returns the id of the page on screen, such as "cart" or "product.single", and renders the component again when the shopper navigates.

hookBeginnerlive demo
RouteId

The named list of every engine page id, so code compares with RouteId.CART instead of typing the string "cart".

constantBeginnerlive demo
registry

The shared name-to-component table the engine consults for a few swappable parts: the product card, the product gallery and home blocks.

objectBeginnerlive demo
Component

Renders the component registered under a name, passing every other prop to it, or a fallback when nothing is registered there.

componentBeginnerlive demo
useComponent

Return the component registered under a name, or the one it replaced, so you render it yourself with typed props.

hookBeginnerlive demo
defineComponent

Registers a component under a name when its file loads, and returns the same component so it can also be imported and rendered directly.

functionBeginnerlive demo
registerComponents, overrideComponents

Register or override many named components in one call, from an object whose keys are names and whose values are components.

functionBeginnerlive demo
ComponentRegistry

The class behind registry. A new instance is a private registry that engine components never read, useful in tests and tooling.

classAdvancedlive demo
notFound, redirect, unauthorized

Throw helpers for route loaders: stop and show the not-found page, send the visitor to another address, or refuse a guest.

functionAdvancedlive demo
orThrow, orUnauthorized

Wrap an API call in a loader: orThrow turns any failure into a not-found error, orUnauthorized turns a 401 or 403 into the unauthorized flow.

functionAdvancedlive demo
NotFoundError, RedirectError, UnauthorizedError

The error classes behind the loader helpers, so an error screen can tell a missing page, a redirect and a refused guest apart.

classAdvanced
SettingsError

The error thrown when a request has no store settings; left uncaught at the root it becomes the "Store Unavailable" page.

classAdvanced
LinkProvider

Tells the engine's Link which real anchor component to render; TwilightProvider supplies TanStack Router's, and tests can supply a plain one.

providerAdvancedlive demo
useLinkAdapter

Returns the anchor component the nearest LinkProvider supplies, and throws LinkProviderError when there is no provider above.

hookAdvancedlive demo
createLinkWithAdapter

Builds a link component bound to one adapter, which renders without any LinkProvider above it.

functionAdvanced
NavigationProvider

Supplies the function useNavigate() returns to everything below it; TwilightProvider mounts one for TanStack Router, and tests can mount their own.

providerAdvancedlive demo
NavigationInterceptor

Turns clicks on ordinary links to this store, including links inside Salla web components, into in-app navigation instead of full reloads.

componentAdvanced
configureNavigation

Replaces what notFound, redirect and unauthorized throw. A framework adapter calls it once; theme code never needs to.

functionAdvanced
useDocumentClassOutput

Returns the merged html and body attributes every useDocumentClass() call has registered, as React props ready to spread.

hookAdvancedlive demo
useDocumentClassContext

Low-level access to the store behind useDocumentClass(): register or remove an html and body descriptor under an id you choose.

hookAdvancedlive demo
DocumentClassProvider

Collects every useDocumentClass() request in its tree and applies the merged classes and attributes to the real body and html elements.

providerAdvanced
routeDocumentSyncs, registerDocumentSync

The per-framework table of components that add route-based body classes, and the function that adds a framework to it.

objectAdvanced
ProductContextProvider

A React context for a product: wrap part of the page once, then read the product anywhere inside it without passing it down.

providerAdvancedlive demo
CartContextProvider

A React context for a cart object: wrap part of the page once, then read the cart anywhere inside it with useCartContext().

providerAdvanced

Also exported here

These exports have no page of their own yet. Their signatures, straight from the engine's type declarations, are in the complete list.

ExportKindImport path
HookNameenum@salla.sa/twilight-theme-engine
HookDefinitioninterface@salla.sa/twilight-theme-engine
HookHandlertype@salla.sa/twilight-theme-engine
HookHandlerstype@salla.sa/twilight-theme-engine