preact

A Preact expert description: Preact is a lightweight (≈3 kB) React alternative that preserves modern APIs. It helps developers use its component model, hooks, reactive state signals, and compat layer to build high-performance web apps, especially for performance-sensitive, embedded components and size-constrained mobile web scenarios.

Last repository push
GitHub Stars
219
Forks
38
Issues / PRs
1

Installation

Review the source and dependencies with a prompt. A package is available to download.

Install with an AI assistant

Copy the prompt so your assistant can review the pinned revision and dependencies first.

View promptHide prompt
Check whether SkillPI Skill Finder is installed for your current agent. If it is missing, install and enable it using the official instructions at https://github.com/Findskills/skillpi. Then use Skill Finder to locate and install "preact" from this exact SkillPI detail page: https://skillpi.com/skills/deepskill-582b883e931f82fe2d4936000785ece0f536b3b6f3564a66b3c50209121b76df. Verify the upstream source and version against https://github.com/TerminalSkills/skills before installing. If they do not match, stop and report the mismatch. Report the installed path and source version.

Source and setup

github.com

Setup guidance pending

See the original source for supported tools, dependencies, and permissions.

Installation test pending

A Preact expert description: Preact is a lightweight (≈3 kB) React alternative that preserves modern APIs. It helps developers use its component model, hooks, reactive state signals, and compat layer to build high-performance web apps, especially for performance-sensitive, embedded components and size-constrained mobile web scenarios.

0 Downloads

Introduction source: third_party · TerminalSkills · 1.0.0 Reference

SkillPi interpretation

Testing
Not tested

Browse files

Browse files at the source ↗

Original SKILL.md

Open original ↗
Frontmatter
name: preact
description: >-
  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.
license: Apache-2.0
compatibility: ''
metadata:
  author: terminal-skills
  version: 1.0.0
  category: Frontend Development
  tags:
    - react-alternative
    - lightweight
    - fast
    - jsx
    - signals
    - 3kb

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

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)

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

// 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

# 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

Current listing version

1.0.0

Verify the source revision ↗

Safety and assessment details

Quality assessment

Out of 100 · Assessment report from SkillPi LAB.

Scenario Value85/100

Highlights

  • 提供 Preact 框架的专业支持,涵盖组件模型、hooks、signals 响应式状态、React 兼容层等核心能力
  • 适用于性能敏感、嵌入式组件、移动端等高频刚需场景,具有明确实用价值
Trigger Precision90/100

Highlights

  • description 清晰描述 Preact 专家角色,覆盖轻量级 React 替代、3kB 大小、现代 API、性能优化等关键触发点
  • 触发词边界清晰,用户能准确理解 Skill 适用范围
Structure and Standards90/100

Highlights

  • 文档结构完整,包含核心能力、代码示例、安装指南、最佳实践等章节
  • frontmatter 完整,单文件未超限,符合规范要求
Execution Reliability90/100

Highlights

  • 提供完整代码示例(TodoApp、Signals、React Compat),工具来源明确
  • 参数正确,覆盖主要使用场景,执行流程可靠
Evidence Verifiability (mean of the first four)89/100

The arithmetic mean of the first four original scores, rounded to a whole number.

Static text checks

100 / 100 · skillpi-20261123-no-r3-v1

No current rules matched the text.

This score reflects rule matches in the text and is provided for reference before use. It excludes attachments and runtime behavior.

Permissions and checks before use

Automatically summarized from this main document. Matches may be examples or defensive advice; they are not actual permission declarations. Attachments, external dependencies and runtime behavior are not covered.

  • Install or fetch external dependencies

    Use official sources and pin versions. Check install scripts in an isolated environment. This document check does not cover code downloaded later.

    Mentioned in main document · lines 123, 127

These notices grant no permissions. Your host tool must still confirm file changes, secrets, external transfers or costs as needed.

Security rating and access scope

safe · Static evidence review; not a runtime safety guarantee.

Before use, confirm and authorize actual file access, external services and network destinations in your host. This review grants no runtime permissions.