|
| 1 | +# React Zero‑UI (Beta) |
| 2 | + |
| 3 | +**Instant UI state updates. ZERO React re‑renders. <1 KB runtime.** |
| 4 | + |
| 5 | +Pre‑render your UI once, flip a `data-*` attribute to update — that's it. |
| 6 | + |
| 7 | +< a href= "https://bundlephobia.com/package/@austinserb/[email protected]" target= "_blank" rel= "noopener noreferrer">< img src= "https://badgen.net/bundlephobia/min/@austinserb/[email protected]" alt= "npm version" /> </ a>< a href= "https://www.npmjs.com/package/@austinserb/react-zero-ui" target= "_blank" rel= "noopener noreferrer">< img src= "https://img.shields.io/npm/v/@austinserb/react-zero-ui" alt= "npm version" /></ a> < a href= "https://opensource.org/licenses/MIT" target= "_blank" rel= "noopener noreferrer">< img src= "https://img.shields.io/badge/License-MIT-yellow.svg" alt= "License: MIT" /></ a>  |
| 8 | + |
| 9 | +--- |
| 10 | + |
| 11 | + |
| 12 | +## 📚 Quick Links |
| 13 | + |
| 14 | +- [⚡️ Quick Start](#️-quick-start) |
| 15 | +- [🏄♂️ Usage](#-usage) |
| 16 | +- [🧬 How it works](#-how-it-works) |
| 17 | +- [✅ Features](#-features) |
| 18 | +- [🏗 Best Practices](#-best-practices) |
| 19 | + |
| 20 | +--- |
| 21 | + |
| 22 | +## 🚀 Live Demo |
| 23 | + |
| 24 | +| Example | Link | What it shows | Link to Code | |
| 25 | +| --------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------- | |
| 26 | +| Interactive menu with render tracker | <a href="https://react-zero-ui.vercel.app/" target="_blank" rel="noopener noreferrer"><strong>Main Demo↗</strong></a> | Compare Zero‑UI vs. React side‑by‑side while toggling a menu. | <a href="https://github.com/Austin1serb/React-Zero-UI/tree/main/examples/demo" target="_blank" rel="noopener noreferrer">Github</a> | |
| 27 | +| React benchmark (10 000 nested nodes) | <a href="https://react-zero-ui.vercel.app/react" target="_blank" rel="noopener noreferrer"><strong>React 10k↗</strong></a> | How long the traditional React render path takes. | <a href="https://github.com/Austin1serb/React-Zero-UI/tree/main/examples/demo/src/app/react" target="_blank" rel="noopener noreferrer">Github</a> | |
| 28 | +| Zero‑UI benchmark (10 000 nested nodes) | <a href="https://react-zero-ui.vercel.app/zero-ui" target="_blank" rel="noopener noreferrer"><strong style="text-align: nowrap;">Zero‑UI 10k↗</strong></a> | Identical DOM, but powered by Zero‑UI's `data-*` switch. | <a href="https://github.com/Austin1serb/React-Zero-UI/tree/main/examples/demo/src/app/zero-ui" target="_blank" rel="noopener noreferrer">Github</a> | |
| 29 | + |
| 30 | +--- |
| 31 | + |
| 32 | +## 🧐 Why Zero‑UI? |
| 33 | + |
| 34 | +Every `setState` in React triggers the full VDOM → Diff → Reconciliation → Paint pipeline. For _pure UI state_ (themes, menus, toggles) that work is wasted. |
| 35 | + |
| 36 | +**Zero‑UI introduces "_PRE‑rendering_":** |
| 37 | + |
| 38 | +1. Tailwind variants for every state are **generated at build‑time**. |
| 39 | +2. The app **pre‑renders once**. |
| 40 | +3. Runtime state changes only **flip a `data-*` attribute on `<body>`**. |
| 41 | + |
| 42 | +Result → **5-10× faster visual updates** with **ZERO additional bundle cost**. |
| 43 | + |
| 44 | +### 📊 Micro‑benchmarks (Apple M1) |
| 45 | + |
| 46 | +| Nodes updated | React state | Zero‑UI | Speed‑up | |
| 47 | +| ------------- | ----------- | ------- | -------- | |
| 48 | +| 10,000 | \~50 ms | \~5 ms | **10×** | |
| 49 | +| 25,000 | \~180 ms | \~15 ms | **12×** | |
| 50 | +| 50,000 | \~300 ms | \~20 ms | **15×** | |
| 51 | + |
| 52 | +Re‑run these numbers yourself via the links above. |
| 53 | + |
| 54 | +--- |
| 55 | + |
| 56 | +## ⚡️ Quick Start |
| 57 | + |
| 58 | +> **Prerequisite:** Tailwind CSS v4 must already be initialized in your project. |
| 59 | +
|
| 60 | +```bash |
| 61 | +# Inside an existing *Next.js (App Router)* or *Vite* repo |
| 62 | +npx create-zero-ui |
| 63 | +``` |
| 64 | + |
| 65 | +That's it — the CLI patch‑installs the required Babel & PostCSS plugins and updates `configs` for you. |
| 66 | + |
| 67 | +### Manual Install |
| 68 | + |
| 69 | +```bash |
| 70 | +npm install @austinserb/react-zero-ui |
| 71 | +``` |
| 72 | + |
| 73 | +Then follow **Setup →** for your bundler. |
| 74 | + |
| 75 | +--- |
| 76 | + |
| 77 | +## 🔧 Setup |
| 78 | + |
| 79 | +### Vite |
| 80 | + |
| 81 | +```js |
| 82 | +// vite.config.* |
| 83 | +import { zeroUIPlugin } from '@austinserb/react-zero-ui/vite'; |
| 84 | + |
| 85 | +export default { |
| 86 | + // ❗️Remove the default `tailwindcss()` plugin — Zero‑UI extends it internally |
| 87 | + plugins: [zeroUIPlugin()], |
| 88 | +}; |
| 89 | +``` |
| 90 | + |
| 91 | +### Next.js (App Router) |
| 92 | + |
| 93 | +1. **Spread `bodyAttributes` on `<body>`** in your root layout. |
| 94 | + |
| 95 | + ```tsx |
| 96 | + // app/layout.tsx |
| 97 | + import { bodyAttributes } from '@austinserb/react-zero-ui/attributes'; |
| 98 | + // or: import { bodyAttributes } from '../.zero-ui/attributes'; |
| 99 | + |
| 100 | + export default function RootLayout({ children }) { |
| 101 | + return ( |
| 102 | + <html lang="en"> |
| 103 | + <body {...bodyAttributes}>{children}</body> |
| 104 | + </html> |
| 105 | + ); |
| 106 | + } |
| 107 | + ``` |
| 108 | + |
| 109 | +2. **Add the PostCSS plugin (must come _before_ Tailwind).** |
| 110 | + |
| 111 | + ```js |
| 112 | + // postcss.config.js |
| 113 | + module.exports = { plugins: { '@austinserb/react-zero-ui/postcss': {}, tailwindcss: {} } }; |
| 114 | + ``` |
| 115 | + |
| 116 | +--- |
| 117 | + |
| 118 | +## 🏄♂️ Usage |
| 119 | + |
| 120 | + |
| 121 | + |
| 122 | +--- |
| 123 | + |
| 124 | +## 🛠 API |
| 125 | + |
| 126 | +### `useUI(key, defaultValue)` |
| 127 | + |
| 128 | +```ts |
| 129 | +const [staleValue, setValue] = useUI<'open' | 'closed'>('sidebar', 'closed'); |
| 130 | +``` |
| 131 | + |
| 132 | +- `key` → becomes `data-{key}` on `<body>`. |
| 133 | +- `defaultValue` → optional, prevents FOUC. |
| 134 | +- **Note:** the returned `staleValue` does **not** update (`useUI` is write‑only). |
| 135 | + |
| 136 | +### Tailwind variants |
| 137 | + |
| 138 | +```jsx |
| 139 | +<div className="sidebar-open:translate-x-0 sidebar-closed:-translate-x-full" /> |
| 140 | +``` |
| 141 | + |
| 142 | +Any `data-{key}="{value}"` pair becomes a variant: `{key}-{value}:`. |
| 143 | + |
| 144 | +--- |
| 145 | + |
| 146 | +## 🧬 How it works |
| 147 | + |
| 148 | +1. **`useUI`** → writes to `data-*` attributes on `<body>`. |
| 149 | +2. **Babel plugin** → scans code, finds every `key/value`, injects them into **PostCSS**. |
| 150 | +3. **PostCSS plugin** → generates static Tailwind classes **at build‑time**. |
| 151 | +4. **Runtime** → changing state only touches the attribute — no VDOM, no reconciliation, no re‑paint. |
| 152 | + |
| 153 | +--- |
| 154 | + |
| 155 | +## ✅ Features |
| 156 | + |
| 157 | +- **Zero React re‑renders** for UI‑only state. |
| 158 | +- **Global setters** — call from any component or util. |
| 159 | +- **Tiny**: < 1 KB gzipped runtime. |
| 160 | +- **TypeScript‑first**. |
| 161 | +- **SSR‑friendly** (Next.js & Vite SSR). |
| 162 | +- **Framework‑agnostic CSS** — generated classes work in plain HTML / Vue / Svelte as well. |
| 163 | + |
| 164 | +--- |
| 165 | + |
| 166 | +## 🏗 Best Practices |
| 167 | + |
| 168 | +1. **UI state only** → themes, layout toggles, feature flags. |
| 169 | +2. **Business logic stays in React** → fetching, data mutation, etc. |
| 170 | +3. **Kebab‑case keys** → e.g. `sidebar-open`. |
| 171 | +4. **Provide defaults** to avoid Flash‑Of‑Unstyled‑Content. |
| 172 | + |
| 173 | +--- |
| 174 | + |
| 175 | +## 🤝 Contributing |
| 176 | + |
| 177 | +PRs & issues welcome! Please read the [Contributing Guide](CONTRIBUTING.md). |
| 178 | + |
| 179 | +--- |
| 180 | + |
| 181 | +## 📜 License |
| 182 | + |
| 183 | +[MIT](LICENSE) © Austin Serb |
| 184 | + |
| 185 | +--- |
| 186 | + |
| 187 | +Built with ❤️ for the React community. If Zero‑UI makes your app feel ZERO fast, please ⭐️ the repo! |
0 commit comments