1- # React Zero-UI
1+ # React Zero-UI (Beta)
22
3- ** Instant UI state updates. ZERO React re-renders. ZERO runtime overhead.** Update the UI instantly, manage global UI state from anywhere. No prop drilling. get started with one command in your existing React app. ``` npx create-zero-ui `` `
3+ ** Instant UI state updates. ZERO React re-renders. ZERO runtime overhead.** Update the UI instantly, manage global UI state from anywhere. No prop drilling. get started with one command in your existing React app. ` npx create-zero-ui `
44
55[ ![ npm version] ( https://img.shields.io/npm/v/@austinserb/react-zero-ui )] ( https://www.npmjs.com/package/@austinserb/react-zero-ui )
66[ ![ License: MIT] ( https://img.shields.io/badge/License-MIT-yellow.svg )] ( https://opensource.org/licenses/MIT )
@@ -14,7 +14,7 @@ Traditional React state triggers RE-renders for every UI change. Switching theme
1414Zero-UI bypasses React entirely for pure UI state. Instead of re-renders, it:
1515
1616- Pre-renders CSS styles and keeps them in the DOM
17- - For state changes it flips a ``` data-* `` ` attribute key.
17+ - For state changes it flips a ` data-* ` attribute key.
1818- Thats it.
1919
2020** Result:** UI updates that are 10-50x faster.
@@ -23,11 +23,11 @@ Zero-UI bypasses React entirely for pure UI state. Instead of re-renders, it:
2323
2424Apple M1
2525
26- | Nodes | React State | Zero-UI | Improvement |
27- | ------- | ------------------ | --------- | ------------- |
28- | 1,000 | ~ 50ms | ~ 5ms | 10x faster |
29- | 5,000 | ~ 180ms | ~ 15ms | 12x faster |
30- | 10,000 | ~ 400ms | ~ 20ms | 20x faster |
26+ | Nodes | React State | Zero-UI | Improvement |
27+ | ------ | ----------- | ------- | ----------- |
28+ | 1,000 | ~ 50ms | ~ 5ms | 10x faster |
29+ | 5,000 | ~ 180ms | ~ 15ms | 12x faster |
30+ | 10,000 | ~ 400ms | ~ 20ms | 20x faster |
3131
3232## Quick Start
3333
@@ -36,7 +36,7 @@ Apple M1
3636CLI script - in your existing Next or Vite App's root:
3737
3838``` bash
39- npx create-zero-ui
39+ npx create-zero-ui
4040```
4141
4242## Manual Installation
@@ -49,34 +49,34 @@ npm install @austinserb/react-zero-ui
4949
5050** Prerequisites:** Tailwind v4 must be initialized. [ tailwind set up ] ( "tailwind.com" )
5151
52-
5352#### Vite
5453
5554``` js
5655// vite.config.*
5756import { zeroUIPlugin } from ' @austinserb/react-zero-ui/vite' ;
5857
5958export default {
60- // *REMOVE TAILWIND PLUGIN* Zero-UI extends tailwinds plug-in
61- plugins: [zeroUIPlugin ()]
62- }
59+ // *REMOVE TAILWIND PLUGIN* Zero-UI extends tailwinds plug-in
60+ plugins: [zeroUIPlugin ()],
61+ };
6362```
6463
6564#### Next.js
6665
6766#### 1. Spread bodyAttributes on ` <body> ` in Layout
6867
6968``` jsx
70- import { bodyAttributes } from " @zero-ui/attributes" ;
69+ import { bodyAttributes } from ' @zero-ui/attributes' ;
7170// or
72- import { bodyAttributes } from " ../.zero-ui/attributes" ;
71+ import { bodyAttributes } from ' ../.zero-ui/attributes' ;
7372
7473export default function RootLayout ({ children }) {
75- return (
76- < html>
77- < body {... bodyAttributes}> {children}< / body>
78- < / html>
79- )}
74+ return (
75+ < html>
76+ < body {... bodyAttributes}> {children}< / body>
77+ < / html>
78+ );
79+ }
8080```
8181
8282#### 2. Add PostCSS Plugin
@@ -110,7 +110,7 @@ function ThemeToggle() {
110110**Consume the state in any component with tailwind!**
111111
112112` ` ` jsx
113- className = " theme-light:bg-white theme-dark:bg-black"
113+ className = ' theme-light:bg-white theme-dark:bg-black' ;
114114` ` `
115115
116116**Mutate the state in any component!**
@@ -126,24 +126,28 @@ function UnrelatedPage()
126126
127127**Use with complex Tailwind Variants**
128128
129-
130129` ` ` jsx
131- clasName = " md:theme-dark:bg-black md:peer-checked:theme-light:hidden"
130+ clasName = ' md:theme-dark:bg-black md:peer-checked:theme-light:hidden' ;
132131` ` `
133132
134133## How It Works
135134
1361351. **State Store**: The ` useUI ` hook writes to ` data -* ` attributes on the ` <body >` tag instead of React state
136+
137137 ` ` ` html
138- <body data-theme = " dark" data-accent = " blue" data-sidebar = " open" >
138+ <body
139+ data-theme = " dark"
140+ data-accent = " blue"
141+ data-sidebar = " open" ></body >
139142 ` ` `
140143
1411442. **Babel Transform**: Automatically detects all ` useUI ` variants in your code during build
142145
1431463. **PostCSS Plugin**: Generates Tailwind variant classes for every detected state
147+
144148 ` ` ` css
145149 .theme - dark \:bg - gray - 900 {
146- background - color : rgb (17 24 39 );
150+ background - color : rgb (17 24 39 );
147151 }
148152 ` ` `
149153
@@ -163,7 +167,7 @@ const [staleValue, setValue] = useUI('theme', 'light');
163167- ` defaultValue ` : Initial value if not set
164168- Returns: ` [staleValue , setValue ]`
165169
166- **note:** normaly used as const ``` const [,setValue]=useUI()``` to denote that the value is stale and will not update
170+ **note:** normaly used as const ` const [,setValue]= useUI ()` to denote that the value is stale and will not update
167171
168172### Tailwind Variants
169173
@@ -191,7 +195,7 @@ Use the pattern `{key}-{value}:` as a Tailwind variant:
1911952. **Not for business logic**: Keep using React state for data that affects logic
1921963. **Consistent naming**: Prefer kebab-case for keys ( ` sidebar - state ` , not ` sidebarState ` )
1931974. **Default values**: Always provide default value for
194- ``` useUI('key', 'value')`` ` to avoid FOUC.
198+ ` useUI (' key' , ' value' )` to avoid FOUC.
195199
196200## Contributing
197201
0 commit comments