useStudioSelection
useStudioSelection returns what the merchant has selected in Weaverse Studio: a page item, or a theme settings group. Use it to reveal UI that is normally hidden while the merchant edits it, such as opening a newsletter popup when its settings group is selected.
Import
Type
Return Value
An item and a theme group are never selected at the same time, so at most one field is non-null. Both are
null:
- on the live storefront, outside Studio
- during server rendering and hydration
- outside a Weaverse root
Setup
The selection store is mounted bywithWeaverse, which wraps your root Layout. No other setup is needed. If the root Layout isn’t wrapped, the hook keeps returning the empty selection and the SDK logs a warning in Studio.
Example
Open a popup while its settings group is selected in Studio’s theme settings:app/components/newsletter-popup.tsx
The Next.js adapter exports the same hook from
@weaverse/hydrogen/next. There, WeaverseNextRootProvider mounts the store.