Stacks Composables
90+ reactive composables for STX templates. All are auto-imported in STX templates.
Key Path
- Core package:
storage/framework/core/composables/src/
Core Reactive Primitives
// From _shared.ts
type MaybeRef<T> = T | Ref<T>
type MaybeRefOrGetter<T> = T | Ref<T> | (() => T)
unref(val) // unwrap Ref
toValue(val) // unwrap Ref or getter
isRef(val) // type guard
State & Reactivity
useToggle(initial?)→[Ref<boolean>, toggle]useCounter(initial?)→{ count, increment, decrement, set, reset }useStepper(steps, initial?)→ step navigationusePrevious(value)→ previous valueuseCycleList(list)→ cycle through items
Storage
useStorage(key, defaultValue, storage?)→ persistent RefuseLocalStorage(key, defaultValue)→ localStorage-backed RefuseSessionStorage(key, defaultValue)→ sessionStorage-backed Ref
Time & Date
useNow(options?)→Ref<Date>(auto-updating)useDateFormat(date, format)→Ref<string>useTimeAgo(date)→ relative time stringuseTimestamp(options?)→Ref<number>useInterval(fn, ms)→ interval controluseIntervalFn(fn, ms)→ interval with pause/resumeuseTimeout(ms)→ timeout controluseTimeoutFn(fn, ms)→ delayed execution
DOM & Browser
useWindowSize()→{ width, height }useWindowScroll()→{ x, y }useWindowFocus()→Ref<boolean>useDocumentVisibility()→Ref<string>useFullscreen(el?)→{ isFullscreen, enter, exit, toggle }useTitle(title)→ document title bindinguseFavicon(url)→ favicon bindinguseCssVar(prop, el?)→ CSS variable bindinguseActiveElement()→ currently focused elementuseTextSelection()→ selected textuseTextDirection()→Ref<'ltr' | 'rtl'>useNavigatorLanguage()→ browser language
Mouse & Touch
useMouse()→{ x, y, sourceType }useMouseInElement(el)→ mouse position relative to elementuseMousePressed()→{ pressed, sourceType }usePointer()→ pointer eventsuseSwipe(el)→ swipe detectionusePointerSwipe(el)→ pointer swipeuseDraggable(el)→ make element draggableuseDropZone(el)→ drop zone detectiononLongPress(el, handler)→ long press detectiononClickOutside(el, handler)→ click outside detection
Sensors
useGeolocation()→{ coords, locatedAt, error }useDeviceMotion()→ acceleration & rotationuseDeviceOrientation()→ alpha, beta, gammauseBattery()→{ charging, chargingTime, level }useDevicePixelRatio()→Ref<number>useScreenSafeArea()→ safe area insets
Observers
useIntersectionObserver(el, callback)→ visibility detectionuseResizeObserver(el, callback)→ size changesuseMutationObserver(el, callback)→ DOM mutationsuseElementBounding(el)→{ top, left, width, height }useElementVisibility(el)→Ref<boolean>useElementHover(el)→Ref<boolean>
Async
useAsyncState(fn, initial)→{ state, isReady, isLoading, error, execute }useAsyncQueue(tasks)→ sequential async executioncomputedAsync(fn)→ async computed valuecomputedEager(fn)→ immediately evaluated computed
Network
useFetch(url, options?)→ fetch wrapper with reactive stateuseWebSocket(url)→ WebSocket connectionuseEventSource(url)→ SSE connectionuseOnline()→Ref<boolean>(network status)
Input & Focus
useFocus(el)→{ focused, focus, blur }useFocusWithin(el)→ any child focuseduseKeyModifier(key)→ modifier key stateusePermission(name)→ permission stateuseShare(options)→ Web Share API
Utilities
useDebounceFn(fn, ms)→ debounced functionuseThrottleFn(fn, ms)→ throttled functionuseDebouncedRef(ref, ms)→ debounced ref updatesuseThrottledRef(ref, ms)→ throttled ref updateswatchDebounced(source, callback, ms)→ debounced watcherwatchThrottled(source, callback, ms)→ throttled watcherwatchOnce(source, callback)→ one-time watcherwhenever(source, callback)→ watch for truthyuntil(source).toBe(value)→ wait for valuesyncRef(refA, refB)→ bidirectional sync
Dark Mode
useDark()→Ref<boolean>usePreferredDark()→ system preferenceusePreferredColorScheme()→ color scheme preference
Media
useMediaQuery(query)→Ref<boolean>usePreferredContrast()→ contrast preferenceusePreferredLanguages()→ language preferencesusePreferredReducedMotion()→ reduce motion preference
State Patterns
createEventHook()→ typed event hookcreateGlobalState(fn)→ shared state across componentscreateSharedComposable(fn)→ shared composable instancerefDefault(ref, defaultValue)→ ref with defaultrefAutoReset(value, ms)→ auto-resetting refmakeDestructurable(obj, arr)→ support both destructuring stylesuseIdle(ms)→ user idle detectionusePageLeave()→ detect page leaveuseFps()→ frames per seconduseMounted()→Ref<boolean>mount statetryOnMounted(fn)→ safe onMounteduseObjectUrl(blob)→ object URL with auto-cleanup
Script & Style Injection
useScriptTag(src, onLoaded?)→ inject<script>useStyleTag(css)→ inject<style>
Math
useAbs,useAverage,useCeil,useClamp,useFloor,useMax,useMin,usePrecision,useRound,useSum,useTruncand,or,logicNot,logicOr
Gotchas
- All composables are auto-imported in STX templates — no import needed
- NEVER use vanilla JS (
var,document.*,window.*) in STX<script>tags - Only use stx-compatible code: signals, composables, directives
- Auto-imports defined in
storage/framework/browser-auto-imports.json - Many composables require a browser environment (won't work server-side)
useStoragepersists to localStorage by default