Command Palette

Search for a command to run...

Назад к скиллам
скилл № 05068

preact

Use when the user asks about Preact, Preact signals, preact/compat, Preact vs React, Preact SSR or cutting bundle size with a React-compatible library…

БесплатноБез исполняемых скриптов
j4flmaoот j4flmao★ 47 звёзд на GitHub

Установить preact в Claude Code и Claude Desktop

Зарегайся, чтобы установить скилл

Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.

  • Открой команду установки в одну строку
  • Сохраняй скиллы в синхронизируемую библиотеку
  • Уведомления, когда скиллы обновляются
Зарегаться бесплатноУ меня уже есть аккаунт

Об этом скилле

Preact

Purpose

Build ultra-lightweight Preact applications using signals for reactive state, compat layer for React interop, and hooks for component logic — all under 3kB.

Agent Protocol

Trigger

Exact user phrases: "Preact setup", "Preact signal", "Preact hooks", "Preact project", "Preact vs React", "Preact SSR", "preact app".

Input Context

Before activating, verify:

  • package.json has preact dependency (or preact/compat).
  • Whether the project uses Vite, WMR, or manual bundler.
  • If React interop is needed (preact/compat).

Output Artifact

No file output. Produces code snippets, config examples, and structural guidance as text.

Response Format

Config:

// vite.config.ts
import { defineConfig } from 'vite'
import preact from '@preact/preset-vite'
export default defineConfig({ plugins: [preact()] })

Code: show component, signal, and hook definitions inline. No import statements.

No preamble. No postamble. No explanations. Compress output — why use many token when few do trick.

Completion Criteria

  • Entry point uses render() from preact (not ReactDOM).
  • Stateful logic uses signals (@preact/signals) for local/global state.
  • Hooks follow Preact compatibility (useEffect, useState, useMemo all work).
  • JSX uses h pragma or compat layer.
  • Bundle size is monitored — no heavy React-for-Preact swaps.
  • SSR uses preact-render-to-string.
  • Class components avoided (functional + hooks preferred).

Max Response Length

~4096 tokens.

Architecture Decision Trees

State Management Decision

What type of state?
  Local UI state (toggle, input) -> useSignal() from @preact/signals
  Shared across few siblings -> Props lifting + signals
  Global application state -> Signals in a shared module file
  Server/async state -> useSWR or TanStack Query (via compat)
  Complex form state -> useReducer from preact/hooks

React library using state? -> Use preact/compat aliasing + their API

React Compatibility Decision

Does the project use React ecosystem libraries?
  No -> Use Preact natively (smallest bundle)
  Yes -> What libraries?
    React Router -> preact/compat aliasing works
    TanStack Query -> preact/compat aliasing works
    Radix UI -> preact/compat may have issues — test first
    Framer Motion -> Known compat issues — consider alternatives

Workflow

Step 1: Setup with Vite

// vite.config.ts
import { defineConfig } from 'vite'
import preact from '@preact/preset-vite'

export default defineConfig({
  plugins: [preact()]
})
// src/main.tsx
import { render } from 'preact'
import { App } from './app'

render(<App />, document.getElementById('app')!)

Step 2: Signals for State

import { signal, computed } from '@preact/signals'

const count = signal(0)
const doubled = computed(() => count.value * 2)

function Counter() {
  return (
    <div>
      <p>Count: {count}</p>
      <p>Doubled: {doubled}</p>
      <button onClick={() => count.value++}>+1</button>
    </div>
  )
}

Step 3: Signal Patterns

// Global signals in module
// store/cart.ts
import { signal, computed } from '@preact/signals'

export const cartItems = signal<CartItem[]>([])
export const cartCount = computed(() => cartItems.value.reduce((sum, i) => sum + i.qty, 0))
export const cartTotal = computed(() => cartItems.value.reduce((sum, i) => sum + i.price * i.qty, 0))

export function addItem(item: CartItem) {
  cartItems.value = [...cartItems.value, item]
}

// Signals with side effects
import { effect } from '@preact/signals'
effect(() => {
  console.log('Cart updated:', cartItems.value)
  localStorage.setItem('cart', JSON.stringify(cartItems.value))
})

Step 4: Hooks (React-compatible)

import { useState, useEffect, useMemo } from 'preact/hooks'

function Timer() {
  const [seconds, setSeconds] = useState(0)

  useEffect(() => {
    const id = setInterval(() => setSeconds(s => s + 1), 1000)
    return () => clearInterval(id)
  }, [])

  return <div>{seconds}s elapsed</div>
}

Step 5: Preact Compat (React interop)

// Replace React imports with preact/compat
import React from 'preact/compat'
import ReactDOM from 'preact/compat'
// Or in vite.config:
// resolve: { alias: { react: 'preact/compat', 'react-dom': 'preact/compat' } }

Step 6: SSR

import { render } from 'preact-render-to-string'
import { App } from './app'

const html = render(<App />)
// Inject into HTML template and serve

Step 7: Code Splitting

import { lazy, Suspense } from 'preact/compat'

const Dashboard = lazy(() => import('./dashboard'))
const Settings = lazy(() => import('./settings'))

function App() {
  return (
    <Suspense fallback={<div>Loading...</div>}>
      <Dashboard />
    </Suspense>
  )
}

Common Pitfalls

  1. Using ReactDOM APIs: Preact uses render() from preact, not ReactDOM.createRoot().
  2. Missing compat alias: Without preact/compat aliasing,
Полный SKILL.md на GitHub

Разрешённые инструменты

Инструменты, которые скиллу разрешено вызывать.

Без ограничений — скилл может использовать любой инструмент.

Вложенные файлы

  • references/preact-advanced.md
  • references/preact-architecture.md
  • references/preact-deployment.md
  • references/preact-fundamentals.md
  • references/preact-setup.md
  • references/preact-vs-react.md

FAQ

Что делает скилл preact?

Use when the user asks about Preact, Preact signals, preact/compat, Preact vs React, Preact SSR or cutting bundle size with a React-compatible library. Produces Preact components, signal-based state and compat aliasing. Not for React-specific architecture (use react-architecture).

Как установить скилл preact?

Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.

Скилл preact запускает скрипты?

Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.

Похожие скиллы

Сравнить preact с