MCPcopy
hub / github.com/preactjs/preact

github.com/preactjs/preact @10.29.3 sqlite

repository ↗ · DeepWiki ↗ · release 10.29.3 ↗
2,393 symbols 4,970 edges 246 files 132 documented · 6%
README

Preact

Fast 3kB alternative to React with the same modern API.

All the power of Virtual DOM components, without the overhead:

  • Familiar React API & patterns: ES6 Class, hooks, and Functional Components
  • Extensive React compatibility via a simple [preact/compat] alias
  • Everything you need: JSX, VDOM, [DevTools], HMR, SSR.
  • Highly optimized diff algorithm and seamless hydration from Server Side Rendering
  • Supports all modern browsers and IE11
  • Transparent asynchronous rendering with a pluggable scheduler

💁 More information at the Preact Website ➞

[![npm](https://img.shields.io/npm/v/preact.svg)](https://www.npmjs.com/package/preact) [![Preact Slack Community](https://img.shields.io/badge/Slack%20Community-preact.slack.com-blue)](https://chat.preactjs.com) [![OpenCollective Backers](https://opencollective.com/preact/backers/badge.svg)](#backers) [![OpenCollective Sponsors](https://opencollective.com/preact/sponsors/badge.svg)](#sponsors) [![coveralls](https://img.shields.io/coveralls/preactjs/preact/main.svg)](https://coveralls.io/github/preactjs/preact) [![gzip size](https://img.badgesize.io/https://unpkg.com/preact/dist/preact.min.js?compression=gzip&label=gzip)](https://unpkg.com/preact/dist/preact.min.js) [![brotli size](https://img.badgesize.io/https://unpkg.com/preact/dist/preact.min.js?compression=brotli&label=brotli)](https://unpkg.com/preact/dist/preact.min.js)

You can find some awesome libraries in the awesome-preact list :sunglasses:


Getting Started

💁 Note: You don't need ES2015 to use Preact... but give it a try!

Tutorial: Building UI with Preact

With Preact, you create user interfaces by assembling trees of components and elements. Components are functions or classes that return a description of what their tree should output. These descriptions are typically written in JSX (shown underneath), or HTM which leverages standard JavaScript Tagged Templates. Both syntaxes can express trees of elements with "props" (similar to HTML attributes) and children.

To get started using Preact, first look at the render() function. This function accepts a tree description and creates the structure described. Next, it appends this structure to a parent DOM element provided as the second argument. Future calls to render() will reuse the existing tree and update it in-place in the DOM. Internally, render() will calculate the difference from previous outputted structures in an attempt to perform as few DOM operations as possible.

import { h, render } from 'preact';
// Tells babel to use h for JSX. It's better to configure this globally.
// See https://babeljs.io/docs/en/babel-plugin-transform-react-jsx#usage
// In tsconfig you can specify this with the jsxFactory
/** @jsx h */

// create our tree and append it to document.body:
render(
    <main>
        <h1>Hello</h1>
    </main>,
    document.body
);

// update the tree in-place:
render(
    <main>
        <h1>Hello World!</h1>
    </main>,
    document.body
);
// ^ this second invocation of render(...) will use a single DOM call to update the text of the <h1>

Hooray! render() has taken our structure and output a User Interface! This approach demonstrates a simple case, but would be difficult to use as an application grows in complexity. Each change would be forced to calculate the difference between the current and updated structure for the entire application. Components can help here – by dividing the User Interface into nested Components each can calculate their difference from their mounted point. Here's an example:

import { render, h } from 'preact';
import { useState } from 'preact/hooks';

/** @jsx h */

const App = () => {
    const [input, setInput] = useState('');

    return (





Do you agree to the statement: "Preact is awesome"?


            <input value={input} onInput={e => setInput(e.target.value)} />



    );
};

render(<App />, document.body);

Sponsors

Become a sponsor and get your logo on our README on GitHub with a link to your site. [Become a sponsor]

            SentDM Songsterr Deno

Backers

Support us with a monthly donation and help us continue our activities. [Become a backer]

<img src="https://opencollective.com/preact/backer/2

Extension points exported contracts — how you extend this code

FunctionComponent (Interface)
(no doc) [24 implementers]
compat/src/internal.d.ts
FunctionComponent (Interface)
(no doc) [24 implementers]
src/internal.d.ts
FunctionComponent (Interface)
(no doc) [24 implementers]
src/index-5.d.ts
FunctionComponent (Interface)
(no doc) [24 implementers]
src/index.d.ts
ToggleEvent (Interface)
[MDN Reference](https://developer.mozilla.org/docs/Web/API/ToggleEvent)
src/jsx.d.ts
SnapEvent (Interface)
[MDN Reference](https://developer.mozilla.org/en-US/docs/Web/API/SnapEvent)
src/dom.d.ts
LazyProps (Interface)
(no doc)
compat/test/ts/suspense.tsx
IntrinsicElements (Interface)
(no doc)
test/ts/custom-elements.tsx

Core symbols most depended-on inside this repo

render
called by 1167
test/fixtures/preact.js
rerender
called by 635
test/fixtures/preact.js
setState
called by 254
debug/src/internal.d.ts
div
called by 215
test/_util/dom.js
clearLog
called by 177
test/_util/logCall.js
act
called by 165
test-utils/src/index.js
useState
called by 152
hooks/src/index.js
li
called by 113
test/_util/dom.js

Shape

Function 803
Method 731
Class 557
Interface 301
Enum 1

Languages

TypeScript100%

Modules by API surface

test/browser/components.test.jsx143 symbols
src/jsx.d.ts106 symbols
src/dom.d.ts99 symbols
compat/test/browser/suspense.test.jsx81 symbols
test/browser/fragments.test.jsx74 symbols
test/browser/lifecycles/shouldComponentUpdate.test.jsx73 symbols
test/browser/createContext.test.jsx62 symbols
test/browser/render.test.jsx59 symbols
test/browser/lifecycles/lifecycle.test.jsx57 symbols
test/ts/preact.tsx56 symbols
src/index.d.ts45 symbols
src/index-5.d.ts45 symbols

Dependencies from manifests, versioned

@actions/github6.0.0 · 1×
@actions/glob0.5.0 · 1×
@babel/core7.26.0 · 1×
@babel/plugin-proposal-class-properties7.0.0-beta.55 · 1×
@babel/plugin-proposal-decorators7.4.0 · 1×
@babel/plugin-transform-react-jsx7.25.9 · 1×
@babel/plugin-transform-react-jsx-source7.25.9 · 1×
@babel/preset-env7.26.0 · 1×
@babel/register7.25.9 · 1×
@material-ui/core4.9.5 · 1×
@reduxjs/toolkit2.2.3 · 1×
@types/chai5.0.1 · 1×

For agents

$ claude mcp add preact \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact