This repository contains React Zero-UI, a library for global UI state without React re-renders. Use these tips when working with the codebase or generating examples.
useUI()writes todocument.body.datasetusing keys you specify.
const [staleValue, setValue] = useUI<'open' | 'closed'>('sidebar', 'closed');key→ becomesdata-{key}on<body>(e.g.,sidebar→data-sidebar="closed").defaultValue→ used for SSR to avoid FOUC. Added to the body as a data-attribute. at build time.- The first value is always stale — do NOT rely on it for reactive updates.
- Consumption is done strictly with tailwind variant classNames:
<div className="sidebar-open:translate-x-0 sidebar-closed:-translate-x-full" />-
Build-time tooling scans all
useUI()keys and values, then generates matching Tailwind variants. -
At runtime, calling the setter updates the
data-*attribute on<body>immediately. No VDOM. No re-renders.
- ✅ Use
useUI()only for UI state: themes, layout flags, open/closed toggles, etc. - ✅ Prefer kebab-case keys: e.g.
sidebar-open,theme-dark. - ✅ Always provide a
defaultValue: prevents FOUC and enables SSR. - ✅ Do NOT use the first value from
useUI()for logic — it DOES NOT UPDATE. - ✅ You can call setters from anywhere in the app — no prop drilling or context needed.
- ✅ Tailwind classes must use
key-value:pattern:theme-dark:bg-blackaccent-blue:text-blue-500sidebar-open:translate-x-0
// Set state
const [, setTheme] = useUI<'light' | 'dark'>('theme', 'light');
<button onClick={() => setTheme('dark')}>Switch to dark</button>;<!-- React component with Tailwind variant -->
<div className="theme-light:bg-white theme-dark:bg-black" />const [, setTheme] = useUI<'light' | 'dark'>('theme', 'light');
// Simply pass a ref to the element
<div
ref={setTheme.ref}
className="theme-light:bg-white theme-dark:bg-black"
/>;Now the data-* will flip on that element, and the styles will be scoped to that element, or its children.
- ❌ Do not pass anything to the StateKey or InitialValue that is not a string or does not resolve to a string.
- ❌ Don't use
useUI()for business logic or data fetching - ❌ Don't rely on the first tuple value for reactivity
- ❌ Don't use camelCase keys (will break variant generation)
React Zero-UI is a ZERO re-render UI state engine with global state baked in. It replaces traditional VDOM cycles with data-* attribute flips and compile-time CSS. No React context. No prop drilling. No runtime cost.
Think of it as writing atomic Tailwind variants for every UI state — but flipping them dynamically at runtime without re-rendering anything.