Preact — Fast 3kB Alternative to React

You are an expert in Preact, the lightweight React alternative with the same modern API in just 3kB. You help developers build performant web applications using Preact's component model, hooks, signals for reactive state, and compat layer for React ecosystem compatibility — ideal for performance-critical apps, embedded widgets, and mobile web where bundle size matters.

25 stars

Best use case

Preact — Fast 3kB Alternative to React is best used when you need a repeatable AI agent workflow instead of a one-off prompt.

You are an expert in Preact, the lightweight React alternative with the same modern API in just 3kB. You help developers build performant web applications using Preact's component model, hooks, signals for reactive state, and compat layer for React ecosystem compatibility — ideal for performance-critical apps, embedded widgets, and mobile web where bundle size matters.

Teams using Preact — Fast 3kB Alternative to React should expect a more consistent output, faster repeated execution, less prompt rewriting.

When to use this skill

  • You want a reusable workflow that can be run more than once with consistent structure.

When not to use this skill

  • You only need a quick one-off answer and do not need a reusable workflow.
  • You cannot install or maintain the underlying files, dependencies, or repository context.

Installation

Claude Code / Cursor / Codex

$curl -o ~/.claude/skills/preact/SKILL.md --create-dirs "https://raw.githubusercontent.com/ComeOnOliver/skillshub/main/skills/TerminalSkills/skills/preact/SKILL.md"

Manual Installation

  1. Download SKILL.md from GitHub
  2. Place it in .claude/skills/preact/SKILL.md inside your project
  3. Restart your AI agent — it will auto-discover the skill

How Preact — Fast 3kB Alternative to React Compares

Feature / AgentPreact — Fast 3kB Alternative to ReactStandard Approach
Platform SupportNot specifiedLimited / Varies
Context Awareness High Baseline
Installation ComplexityUnknownN/A

Frequently Asked Questions

What does this skill do?

You are an expert in Preact, the lightweight React alternative with the same modern API in just 3kB. You help developers build performant web applications using Preact's component model, hooks, signals for reactive state, and compat layer for React ecosystem compatibility — ideal for performance-critical apps, embedded widgets, and mobile web where bundle size matters.

Where can I find the source code?

You can find the source code on GitHub using the link provided at the top of the page.

SKILL.md Source

# Preact — Fast 3kB Alternative to React

You are an expert in Preact, the lightweight React alternative with the same modern API in just 3kB. You help developers build performant web applications using Preact's component model, hooks, signals for reactive state, and compat layer for React ecosystem compatibility — ideal for performance-critical apps, embedded widgets, and mobile web where bundle size matters.

## Core Capabilities

### Components and Hooks

```tsx
import { h, render } from "preact";
import { useState, useEffect, useRef, useMemo } from "preact/hooks";

function TodoApp() {
  const [todos, setTodos] = useState<{ id: number; text: string; done: boolean }[]>([]);
  const [input, setInput] = useState("");
  const inputRef = useRef<HTMLInputElement>(null);

  const remaining = useMemo(() => todos.filter(t => !t.done).length, [todos]);

  const addTodo = () => {
    if (!input.trim()) return;
    setTodos([...todos, { id: Date.now(), text: input, done: false }]);
    setInput("");
    inputRef.current?.focus();
  };

  const toggle = (id: number) => {
    setTodos(todos.map(t => t.id === id ? { ...t, done: !t.done } : t));
  };

  return (
    <div>
      <h1>Todos ({remaining} remaining)</h1>
      <input ref={inputRef} value={input} onInput={e => setInput((e.target as HTMLInputElement).value)}
        onKeyDown={e => e.key === "Enter" && addTodo()} />
      <button onClick={addTodo}>Add</button>
      <ul>
        {todos.map(t => (
          <li key={t.id} style={{ textDecoration: t.done ? "line-through" : "none" }}
            onClick={() => toggle(t.id)}>{t.text}</li>
        ))}
      </ul>
    </div>
  );
}

render(<TodoApp />, document.getElementById("app")!);
```

### Signals (Fine-Grained Reactivity)

```tsx
import { signal, computed, effect } from "@preact/signals";

// Global reactive state — no context providers needed
const count = signal(0);
const doubled = computed(() => count.value * 2);

// Effects run when dependencies change
effect(() => {
  document.title = `Count: ${count.value}`;
});

function Counter() {
  // Signal directly in JSX — only this text node updates, not entire component
  return (
    <div>
      <p>Count: {count}</p>
      <p>Doubled: {doubled}</p>
      <button onClick={() => count.value++}>+</button>
    </div>
  );
}

// No re-render of Counter component — signal updates the DOM text node directly
```

### React Compatibility

```tsx
// preact/compat provides React-compatible API
// In package.json or bundler config:
// "alias": { "react": "preact/compat", "react-dom": "preact/compat" }

// Now React libraries work with Preact:
import { useQuery } from "@tanstack/react-query";  // Works!
import { motion } from "framer-motion";            // Works!

// Most React component libraries work out of the box with the compat layer
```

## Installation

```bash
# New project
npm create preact                          # Official CLI

# Add to existing Vite project
npm install preact
# vite.config.ts: alias { "react": "preact/compat", "react-dom": "preact/compat" }

# Signals
npm install @preact/signals
```

## Best Practices

1. **Signals for state** — Use `@preact/signals` for shared state; no Context needed, fine-grained DOM updates
2. **React compat for ecosystem** — Alias `react` to `preact/compat`; use React component libraries without modification
3. **3kB advantage** — Preact shines in performance-critical contexts: embedded widgets, mobile web, slow connections
4. **Same API as React** — useState, useEffect, useRef, useMemo all work identically; easy migration
5. **No synthetic events** — Preact uses native DOM events; slightly different from React's event system
6. **Prerender for SSG** — Use `preact-render-to-string` for server rendering; or use Fresh (Deno) for full SSR
7. **HTM for no-build** — Use `htm` tagged template literals instead of JSX; works without a build step
8. **Bundle analysis** — Compare with React: Preact (3kB) vs React+ReactDOM (42kB); Preact wins on initial load

Related Skills

fastify-plugin-creator

25
from ComeOnOliver/skillshub

Fastify Plugin Creator - Auto-activating skill for Backend Development. Triggers on: fastify plugin creator, fastify plugin creator Part of the Backend Development skill category.

fastapi-router-creator

25
from ComeOnOliver/skillshub

Fastapi Router Creator - Auto-activating skill for Backend Development. Triggers on: fastapi router creator, fastapi router creator Part of the Backend Development skill category.

fastapi-ml-endpoint

25
from ComeOnOliver/skillshub

Fastapi Ml Endpoint - Auto-activating skill for ML Deployment. Triggers on: fastapi ml endpoint, fastapi ml endpoint Part of the ML Deployment skill category.

upgrading-react-native

25
from ComeOnOliver/skillshub

Upgrades React Native apps to newer versions by applying rn-diff-purge template diffs, updating package.json dependencies, migrating native iOS and Android configuration, resolving CocoaPods and Gradle changes, and handling breaking API updates. Use when upgrading React Native, bumping RN version, updating from RN 0.x to 0.y, or migrating Expo SDK alongside a React Native upgrade.

react-native-brownfield-migration

25
from ComeOnOliver/skillshub

Provides an incremental adoption strategy to migrate native iOS or Android apps to React Native or Expo using @callstack/react-native-brownfield for initial setup. Use when planning migration steps, packaging XCFramework/AAR artifacts, and integrating them into host apps.

react-native-design

25
from ComeOnOliver/skillshub

Master React Native styling, navigation, and Reanimated animations for cross-platform mobile development. Use when building React Native apps, implementing navigation patterns, or creating performant animations.

vercel-react-native-skills

25
from ComeOnOliver/skillshub

React Native and Expo best practices for building performant mobile apps. Use when building React Native components, optimizing list performance, implementing animations, or working with native modules. Triggers on tasks involving React Native, Expo, mobile performance, or native platform APIs.

react-useeffect

25
from ComeOnOliver/skillshub

React useEffect best practices from official docs. Use when writing/reviewing useEffect, useState for derived values, data fetching, or state synchronization. Teaches when NOT to use Effect and better alternatives.

react-dev

25
from ComeOnOliver/skillshub

This skill should be used when building React components with TypeScript, typing hooks, handling events, or when React TypeScript, React 19, Server Components are mentioned. Covers type-safe patterns for React 18-19 including generic components, proper event typing, and routing integration (TanStack Router, React Router).

react-patterns

25
from ComeOnOliver/skillshub

Modern React patterns and principles. Hooks, composition, performance, TypeScript best practices.

react-nextjs-development

25
from ComeOnOliver/skillshub

React and Next.js 14+ application development with App Router, Server Components, TypeScript, Tailwind CSS, and modern frontend patterns.

react-modernization

25
from ComeOnOliver/skillshub

Upgrade React applications to latest versions, migrate from class components to hooks, and adopt concurrent features. Use when modernizing React codebases, migrating to React Hooks, or upgrading to latest React versions.