|
| 1 | + |
| 2 | +## ⚡️ React Zero-UI |
| 3 | +*The ZERO re-render UI state library* |
| 4 | + |
| 5 | +**The fastest possible UI updates in React. Period.** |
| 6 | +Zero runtime, zero React re-renders, and the simplest developer experience ever. |
| 7 | + |
| 8 | +See the proof in [here](/docs/demo) |
| 9 | + |
| 10 | +<a href="https://bundlephobia.com/package/@react-zero-ui/core@0.2.6" target="_blank" rel="noopener noreferrer"><img src="https://badgen.net/bundlephobia/minzip/@react-zero-ui/core@0.2.6" 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/@react-zero-ui/core" 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>  |
| 11 | + |
| 12 | +--- |
| 13 | + |
| 14 | + |
| 15 | +## 🔥 Core Concept: *"Pre-Rendering"* |
| 16 | + |
| 17 | +Why re-render UI if all states are known at build time? React Zero-UI **pre-renders** UI states once, and flips `data-*` attribute to update - that's it. |
| 18 | + |
| 19 | +**Example:** |
| 20 | + |
| 21 | +```tsx |
| 22 | +const [, setTheme] = useUI("theme", "dark"); |
| 23 | + |
| 24 | +// Flip theme to "light" |
| 25 | +setTheme("light"); // data-theme="light" on body |
| 26 | +``` |
| 27 | + |
| 28 | +Tailwind usage: |
| 29 | + |
| 30 | +```html |
| 31 | +<div class="theme-dark:bg-black theme-light:bg-white">Fast & Reactive</div> |
| 32 | +``` |
| 33 | + |
| 34 | +--- |
| 35 | + |
| 36 | +## 🚀 How it Works (Build-Time Magic) |
| 37 | + |
| 38 | +React Zero-UI uses a hyper-optimized AST resolver in development/build-time that scans your codebase for: |
| 39 | + |
| 40 | +* `useUI` and `useScopedUI` hook usage. |
| 41 | +* Any variables resolving to strings (e.g., `'theme'`, `'modal-open'`). |
| 42 | +* Tailwind variant classes (e.g., `theme-dark:bg-black`). |
| 43 | + |
| 44 | +This generates: |
| 45 | + |
| 46 | +* Optimal CSS with scoped variant selectors. |
| 47 | +* Initial data-attributes injected onto the body (zero FOUC). |
| 48 | +* **Zero runtime overhead in production**. |
| 49 | + |
| 50 | +--- |
| 51 | + |
| 52 | +## ⚙️ Installation (Zero-UI CLI) |
| 53 | + |
| 54 | +pre-requisites: |
| 55 | +- Tailwind CSS v4 must already be initialized in your project. |
| 56 | +- Vite or Next.js (App Router) |
| 57 | + |
| 58 | + |
| 59 | +```bash |
| 60 | +npx create-zero-ui |
| 61 | +``` |
| 62 | +> for manual configuration, see [manual installation.](https://github.com/react-zero-ui/core) |
| 63 | +
|
| 64 | +--- |
| 65 | + |
| 66 | +## 🔨 API: `useUI` Hook (Global UI state) |
| 67 | + |
| 68 | +Simple hook mirroring React's `useState`: |
| 69 | + |
| 70 | +```tsx |
| 71 | +import { useUI } from '@react-zero-ui/core'; |
| 72 | + |
| 73 | +const [theme, setTheme] = useUI("theme", "dark"); |
| 74 | +``` |
| 75 | + |
| 76 | +* Flips global `data-theme` attribute on `<body>`. |
| 77 | +* Zero React re-renders. |
| 78 | +* Initial state pre-rendered at build time (no FOUC). |
| 79 | + |
| 80 | +--- |
| 81 | + |
| 82 | +## 🎯 API: `useScopedUI` Hook (Scoped UI state) |
| 83 | + |
| 84 | +Control UI states at the element-level: |
| 85 | + |
| 86 | +```tsx |
| 87 | +import { useScopedUI } from '@react-zero-ui/core'; |
| 88 | + |
| 89 | +const [theme, setTheme] = useScopedUI("theme", "dark"); |
| 90 | + |
| 91 | +// Flips data-theme attribute on the specific ref element |
| 92 | +<div ref={setTheme.ref} data-theme={theme}> |
| 93 | + Scoped UI Here |
| 94 | +</div> |
| 95 | +``` |
| 96 | + |
| 97 | +* Data attribute flips on specific target element. |
| 98 | +* Generates scoped CSS selectors only applying within the target element. |
| 99 | + |
| 100 | +--- |
| 101 | + |
| 102 | +## 🌈 API: CSS Variables Support |
| 103 | + |
| 104 | +Sometimes CSS variables are more efficient. React Zero-UI makes it trivial using the `CssVar` option: |
| 105 | + |
| 106 | +```tsx |
| 107 | +import { useUI, CssVar } from '@react-zero-ui/core'; |
| 108 | + |
| 109 | +const [blur, setBlur] = useUI("blur", "0px", CssVar); |
| 110 | + |
| 111 | +// Flips CSS variable --blur on body |
| 112 | +setBlur("5px"); // body { --blur: 5px } |
| 113 | +``` |
| 114 | + |
| 115 | +**Scoped CSS Variable Example:** |
| 116 | + |
| 117 | +```tsx |
| 118 | +const [blur, setBlur] = useScopedUI("blur", "0px", CssVar); |
| 119 | + |
| 120 | +<div ref={setBlur.ref} style={{ "--blur": blur }}> |
| 121 | + Scoped blur effect. |
| 122 | +</div> |
| 123 | +``` |
| 124 | + |
| 125 | +--- |
| 126 | + |
| 127 | +## 🧪 Experimental: SSR-safe `zeroOnClick` |
| 128 | + |
| 129 | +Enable client-side interactivity **without leaving server components**. |
| 130 | +Just 300 bytes of runtime overhead. |
| 131 | + |
| 132 | +See [experimental](./docs/assets/experimental.md) for more details. |
| 133 | + |
| 134 | +## 📦 Summary of Benefits |
| 135 | + |
| 136 | +* **Zero React re-renders:** Pure CSS-driven UI state. |
| 137 | +* **Pre-rendered UI:** All states injected at build-time. and only loaded when needed. |
| 138 | +* **Tiny footprint:** <350 bytes runtime, zero overhead for CSS states. |
| 139 | +* **SSR-safe interaction:** Static server components, fully interactive. |
| 140 | +* **Amazing DX:** Simple hooks, auto-generated Tailwind variants. |
| 141 | +* **Highly optimized AST resolver:** Fast, cached build process. |
| 142 | + |
| 143 | +React Zero-UI delivers the fastest, simplest, most performant way to handle global and scoped UI state in modern React applications. |
| 144 | + |
| 145 | + |
| 146 | +Made with ❤️ for the React community by [@austinserb](https://github.com/austin1serb) |
0 commit comments