Skip to content

react-zero-ui/core

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Tagline

Frame 342

The fastest possible UI updates in React. Period.

Zero runtime, zero React re-renders, and the simplest developer experience ever. Say goodbye to context and prop-drilling.

bundle size npm version License: MIT CI

๐Ÿ“– See the proof ๐Ÿš€ Quick Start ๐Ÿ“š API Reference ๐Ÿ“‹ Usage Examples ๐Ÿ”„ Migration Guide โ“ FAQ ๐Ÿค Contributing


๐Ÿ”ฅ Core Concept: "Pre-Rendering"

Why re-render UI if all states are known at build time? React Zero-UI pre-renders UI states once ( at no runtime cost ), and flips data-* attributes to update - that's it.

Example:

const [, setTheme] = useUI('theme', 'dark');

// Flip theme to "light"
setTheme('light'); // data-theme="light" on body

Tailwind usage: Anywhere in your app

<div class="theme-dark:bg-black theme-light:bg-white">Fast & Reactive</div>

๐Ÿš€ How it Works (Build-Time Magic)

React Zero-UI uses a hyper-optimized AST resolver in development that scans your codebase for:

  • useUI and useScopedUI hook usage.
  • Any variables resolving to strings (e.g., 'theme', 'modal-open').
  • Tailwind variant classes (e.g. theme-dark:bg-black).

This generates:

  • Optimal CSS with global or scoped variant selectors.
  • Initial data-attributes injected onto the body (zero FOUC).
  • UI state with ease, no prop-drilling.
  • Zero runtime overhead in production.

๐Ÿš€ Quick Start

Zero-UI CLI

Pre-requisites:

npx create-zero-ui

For manual configuration, see Next JS Installation | Vite Installation

That's it. Start your app and see the magic.


๐Ÿ“š API Reference

The Basics:

const [<staleValue>, <setterFunction>] = useUI(<stateKey>, <defaultValue>);
  • stateKey โžก๏ธ becomes data-{stateKey} on <body>.
  • defaultValue โžก๏ธ SSR, prevents FOUC.
  • staleValue โžก๏ธ For scoped UI, set the data-* to the staleValue to prevent FOUC.
  • Note: the returned staleValue does not update (useUI is writeโ€‘only).

๐Ÿ”จ useUI Hook (Global UI State)

Simple hook mirroring React's useState:

import { useUI } from '@react-zero-ui/core';

const [theme, setTheme] = useUI('theme', 'dark');

Features:

  • Flips global data-theme attribute on <body>.
  • Zero React re-renders.
  • Global UI state available anywhere in your app through tailwind variants.

๐ŸŽฏ useScopedUI Hook (Scoped UI State)

Control UI states at the element-level:

+ import { useScopedUI } from '@react-zero-ui/core';

const [theme, setTheme] = useScopedUI("theme", "dark");

// โ—๏ธFlips data-* on the specific ref element
+ <div ref={setTheme.ref}
// โ—๏ธset the data-* to the staleValue to prevent FOUC
+ data-theme={theme}
>
  Scoped UI Here
</div>

Features:

  • Data-* flips on specific target element.
  • Generates scoped CSS selectors only applying within the target element.
  • No FOUC, no re-renders.

๐ŸŒˆ CSS Variables Support

Sometimes CSS variables are more efficient. React Zero-UI makes it trivial by passing the CssVar option:

+ Pass `CssVar` to either hook to use CSS variables

useUI(<cssVariable>, <defaultValue>, CssVar);

automatically adds -- to the Css Variable

Global CSS Variable:

+ import { CssVar } from '@react-zero-ui/core';
const [blur, setBlur] = useUI('blur', '0px', CssVar);
setBlur('5px'); // body { --blur: 5px }

Scoped CSS Variable:

const [blur, setBlur] = useScopedUI('blur', '0px', CssVar);

<div
	ref={setBlur.ref}
	style={{ '--blur': blur }}>
	Scoped blur effect.
</div>;

๐Ÿงช Experimental Features

SSR-safe zeroOnClick

Enable client-side interactivity without leaving server components. Just 300 bytes of runtime overhead.

See experimental for more details.


๐Ÿ“ฆ Summary of Benefits

  • ๐Ÿš€ Zero React re-renders: Pure CSS-driven UI state.
  • โšก๏ธ Pre-rendered UI: All states injected at build-time and only loaded when needed.
  • ๐Ÿ“ฆ Tiny footprint: <350 bytes, zero runtime overhead for CSS states.
  • ๐Ÿ’ซ Amazing DX: Simple hooks, auto-generated Tailwind variants.
  • โš™๏ธ Highly optimized AST resolver: Fast, cached build process.

React Zero-UI delivers the fastest, simplest, most performant way to handle global and scoped UI state in modern React applications. Say goodbye to re-renders and prop-drilling.



๐Ÿ“– Documentation

๐Ÿ“š Complete Guide Collection

Guide Description
๐Ÿ“š API Reference Complete API documentation for all hooks and utilities
๐Ÿ“‹ Usage Examples Practical patterns and real-world use cases
๐Ÿ”„ Migration Guide Step-by-step migration from useState, Context, Redux
๐Ÿ”ง Troubleshooting Common issues and debugging techniques
โ“ FAQ Frequently asked questions and answers
๐Ÿงช Experimental Features SSR-safe server component interactivity

๐Ÿ› ๏ธ Setup Guides

Framework Guide
Next.js App Router Complete Next.js setup with SSR support
Vite + React Vite configuration and optimization

๐ŸŽฏ Learn by Example


๐Ÿค Contributing

We welcome contributions from the community! Whether it's bug fixes, feature requests, documentation improvements, or performance optimizations - every contribution helps make React Zero-UI better.

Get involved:

First time contributor? We have good first issues labeled good-first-issue to help you get started!

Made with โค๏ธ for the React community by @austin1serb