38,992
stars
+0
2,465
forks
388
watchers
3,019
prs
1,959
issues
259
releases
171
discussions
README
!Preact
Fast 4kB 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
- Transparent asynchronous rendering with a pluggable scheduler
💁 More information at the Preact Website ➞
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.
js
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-jsxusage
// In tsconfig you can specify this with the jsxFactory
/ @jsx h /
// create our tree and append it to document.body:
render(
Hello
,
document.body
);
// update the tree in-place:
render(
Hello World!
,
document.body
);
// ^ this second invocation of render(...) will use a single DOM call to update the text of the
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:
js
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"?
setInput(e.target.value)} /
);
};
render(, document.body);
---
Sponsors
Become a sponsor and get your logo on ouTop issues
#1899Uncontrolled input21 comments · 2019-08-27#4416syntax for choosing setting a property vs attribute on elements12 comments · 2024-06-20#678Checking `prop in elem` fails with deferred custom element definitions11 comments · 2017-04-27#3853Add ARIA attribute typings8 comments · 2023-01-06#3649Is it possible to make useDeferredValue to actually do something?7 comments · 2022-08-07#407Main thread is locked up during bootup6 comments · 2016-11-17#4695Support for Document Metadata in Preact4 comments · 2025-02-18#3666[preact/compat] radix-ui Slider component drag points (Thumbs) not working4 comments · 2022-08-12
Discussions
#5354What is the best Oxlint config for a Preact project?1 comments · 2026-11-07#5301Preact 11.0.0 loading report across Node.js, Bun and Deno1 comments · 2026-10-08#5249A11yKit: 15 Zero-Upload WCAG 2.2 / APCA Accessibility & Contrast Tools for Lightweight Preact Apps0 comments · 2026-09-08#5293different behaviors between Preact and React in Mui-x date pickers4 comments · 2026-07-25#5113[removed]0 comments · 2026-06-10#5105Testing Preact `11.0.0-experimental-1`...does ref auto-forwarding not work yet?1 comments · 2026-05-27#5050Build Apps For AI Agent.1 comments · 2026-03-09#4965How to use React component defined as `class Plot extends React.PureComponent<PlotParams> {}`2 comments · 2025-11-28
Latest release
11.2.0 11.2.0 2026-11-06Features - Support scoped custom element registries when rendering into shadow roots (5342, thanks @JoviDeCroock) Fixes - Ignore non-function values for on props instead of registering invalid event handlers (5345, thanks @JoviDeCroock) - Pass a thrown null or undefined to error boundaries without replacing it with a TypeError (5347, thanks @jonkwheeler) - Preserve event handlers on unmounted nodes so events already bubbling can finish (5349, thanks @JoviDeCroock) Performance - Reduce bundle size across core, hooks, and compat (5343, thanks @JoviDeCroock)