Skip to content

react-zero-ui/core

Repository files navigation

Tagline

Frame 342

The fastest possible UI updates in React. Period.

Zero runtime, zero React re-renders, and a simple developer experience. 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 at build time, then flips data-* attributes to update the interface.

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

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

  • useUI and useScopedUI hook usage
  • variables that resolve to strings like 'theme' or 'modal-open'
  • Tailwind variant classes such as theme-dark:bg-black

This generates:

  • optimal CSS with global or scoped variant selectors
  • initial data attributes injected onto the body with no FOUC
  • simple UI state without prop drilling
  • zero runtime overhead in production

Quick Start

Zero-UI CLI

Prerequisites:

npx create-zero-ui

For manual configuration, see Next.js Installation or Vite Installation

Start your app and use Zero-UI.


API Reference

Basic shape:

const [<staleValue>, <setterFunction>] = useUI(<stateKey>, <defaultValue>);
  • stateKey becomes data-{stateKey} on <body>
  • defaultValue supports SSR and helps prevent FOUC
  • staleValue is used for scoped UI so you can set the data-* attribute to prevent FOUC
  • the returned staleValue does not update; useUI is write-only

useUI Hook (Global UI State)

Simple hook with the same shape as React's useState:

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

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

Features:

  • flips a 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:

  • flips data attributes on a specific target element
  • generates scoped CSS selectors that only apply within that element
  • no FOUC and no re-renders

CSS Variables Support

Sometimes CSS variables are more efficient. React Zero-UI supports them 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. About 300 bytes of runtime overhead.

See experimental for more details.


Summary of Benefits

  • zero React re-renders through pure CSS-driven UI state
  • pre-rendered UI with states injected at build time
  • tiny footprint with effectively no runtime overhead for CSS states
  • simple hooks and auto-generated Tailwind variants
  • a fast, cached AST resolver

React Zero-UI is a fast, simple way to handle global and scoped UI state in modern React apps without extra re-renders or prop drilling.


Documentation

Guides

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
FAQ Frequently asked questions and answers
Experimental Features SSR-safe server component interactivity

Setup

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

Examples


Contributing

We welcome bug fixes, feature requests, documentation improvements, and performance work from the community.

Get involved:

First-time contributor? Look for issues labeled good-first-issue.

Made for the React community by @austin1serb
Built with support from Serbyte Web Design & Development

About

Instant global UI state with ZERO re-renders, ZERO runtime, ZERO pain.

Topics

Resources

License

Contributing

Stars

Watchers

Forks

Packages

 
 
 

Contributors