EnadThemeProvider
Runtime theme boundary for component sets, shared playground hashes, and scoped token overrides in the Enad React SDK.
Best for
Import
import { EnadThemeProvider } from "@enadhq/enad-react-sdk/client/theme"When to use it
Use EnadThemeProvider when a running app needs to restore or switch theme state after the initial SDK setup is already in place.
The normal split is:
EnadProviderowns the SDK runtimeEnadThemeProviderowns runtime component-set selection and scoped token CSS
That root runtime now also includes Search GraphQL setup when EnadProvider receives shopper-facing clientConfig. Keep search-backed hooks like useEnadGraphQLQuery() and useEnadGraphQLQueryContext(), plus connected SearchProduct* wrappers from @enadhq/enad-react-sdk/client/search, inside the same root provider rather than creating a second app-level GraphQL client beside it.
That makes EnadThemeProvider the right tool when you want a subtree to pick up a playground share hash, a non-default component set, or direct token overrides.
Composition notes
EnadThemeProvider wraps its children in ComponentSetProvider, then resolves the final runtime theme from:
- explicit props
- decoded hash values
- SDK defaults
In practice that means:
componentSetwins over anycomponentSetstored inhashtokenswins over decoded token values fromhash- if neither is present, the provider falls back to the default component set and default token values
The provider only creates a wrapper element when it needs one. If the resolved state is default and there is no scoped CSS to inject, it can return the children directly. Use the as prop when you want to force a semantic wrapper like section or aside.
State and theming guidance
Treat runtime theming as two separate layers:
- component sets change the structural language of the UI through
data-component-set - hashes or tokens change CSS variables for color, shape, typography, and related theme tokens
That split matters when debugging shared themes. If the restored app does not match the playground, check these in order:
- did the same
hashmake it into the app? - is an explicit
componentSetprop overriding the shared hash value? - are explicit
tokensoverriding decoded values? - is the SDK stylesheet imported so component-set selectors can take effect?
The playground export prefers a hash-based setup snippet for exact restoration of runtime theme state. If the current state contains non-default runtime theme data, the setup guide exports:
const themeHash = "..."<EnadThemeProvider hash={themeHash}>
When the playground also uses a non-default icon adapter or Custom (Iconify) slot overrides, the export pairs that same themeHash with the matching EnadProvider icons={...} setup. EnadThemeProvider restores the runtime theme layer, while the root icon provider restores the icon layer.
Use hash when you want portable, replayable theme state and a snippet that matches the current playground exactly. Use tokens when you want a local override that stays readable in code. Use componentSet when the main goal is to change the structural family, not just the color system.
Examples
Live examples you can edit directly in the sandbox.
Switch the runtime component set
Keep EnadProvider at the root, then use EnadThemeProvider to switch the structural set for a subtree.
Restore a shared playground hash
Use encodeThemeHash to simulate a share URL payload, then restore the same structure and tokens through EnadThemeProvider.
Apply scoped token overrides
Pass tokens directly when you want a local override without going through a saved hash.
Component Sets
Preview the first example across the available component-set presets to compare tone, spacing, and structural defaults.