Open-source project
preactjs/preact avatar
preactjs/preact

Preact 11: a small Virtual DOM library that keeps React's API but splits it across entry points

GitHub describes it as ⚛️ Fast 3kB React alternative with the same modern API. Components & Virtual DOM.. The repository metadata lists JavaScript as its primary language. The metadata lists the MIT license. This article stays within the project description and details documented in the GitHub repository README.

39,005 stars2,464 forksJavaScriptMIT

At a glance

What is it?
Preact gives you components, hooks and JSX through a diffing render() call, with React compatibility moved into a separate preact/compat alias. This guide walks through how render() updates the DOM, where each piece of the API lives in the package, and what you have to configure before React code runs on it.
Who is it for?
Preact fits teams that want React's component, hooks and JSX model in a smaller package and are willing to configure a JSX pragma or jsx-runtime and alias React imports to preact/compat. It is a poor fit if you expect to drop it into an existing React codebase with no build changes.
Can I use it commercially?
Yes. MIT is a permissive licence: you can use, modify and sell software built on it, as long as you keep its copyright and licence notices.
Is it still maintained?
Yes. The repository last received commits 2 days ago.
What is it written in?
Mainly JavaScript, according to GitHub's language statistics.

Answers come from the project's GitHub data, last synced on November 13, 2026, and from our analysis. They are not legal advice.

From daily snapshots

Star history

  • preactjs/preact39,005 ★ · +191
Star history
Repository2026-08-132026-11-13
preactjs/preact38.8k39k

191 Stars in the last 92 days, measured from the daily GitHub snapshot. Compare with other projects

Editorial analysis

render() patches the existing tree instead of rebuilding it

Everything in Preact starts at render(). It takes two arguments: a description of a tree of elements, and a parent DOM element to append that tree to. The first call builds the DOM nodes. Every later call against the same parent reuses what is already there and computes the difference between the previous output and the new one, so that only the DOM operations needed to reach the new state are performed.

The README's opening example shows this with two calls that differ only in the heading text:

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

The second render() changes the text of the existing h1 with a single DOM call. Nothing is torn down and recreated. The project describes this as a highly optimized diff algorithm, and the same mechanism is what lets server-rendered markup be hydrated rather than replaced.

Calling render() at the top level does not scale, so state belongs in components

The top-level render() pattern has a cost the Preact authors state openly: if every change goes through a call at the root, every change forces Preact to compare the entire application against its previous structure. For a heading that is fine. For a real interface with forms, lists and nested panels, it means diffing far more than whatever actually changed.

Components are the answer to that. A component is a function or a class that returns a description of what its part of the tree should output. Once the interface is split into nested components, each one can compute its difference from its own mount point instead of from the document root. The consequence for readers coming from plain DOM scripting is that Preact pays off only when you structure the page as components; a single giant render() call at the top gives you the diffing overhead without the locality that makes it cheap.

Preact supports the same component styles React developers already use: ES6 class components, function components, and hooks. Rendering can also be asynchronous, and the scheduler that decides when queued updates are flushed is pluggable rather than fixed.

JSX only works after you tell the compiler to call h

Preact does not hide its element factory. The function that turns markup into elements is h, and it is exported from the main preact module. JSX written in a file is compiled into calls to some factory function, and unless your build is set up for Preact, that factory will not be h.

The README's examples solve this per file with a pragma comment, /** @jsx h */, placed under the imports. The comments in the first example point to the better option: configure it once globally. In Babel that means the transform-react-jsx plugin's settings, and in TypeScript it means the jsxFactory option in tsconfig. If you skip both the pragma and the global setting, your JSX compiles to calls that Preact did not provide, and the components will not render.

The package also exposes ./jsx-runtime and ./jsx-dev-runtime entry points, both pointing at jsx-runtime/dist/jsxRuntime.mjs, for toolchains that use the automatic JSX runtime instead of a factory pragma.

JSX is not mandatory. The README names HTM as an alternative, which builds the same element trees from standard JavaScript tagged templates, so a page can use Preact without any JSX compilation step at all. The project also notes you do not need ES2015 to use Preact, and links a preact-in-es3 example for that case.

Hooks, debug tooling and test helpers are separate imports

A detail that trips up people porting React code: in Preact, hooks are not exported from the main module. The second README example imports render and h from preact, but useState from a different path:

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

/** @jsx h */

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

	return (
		<div>
			<p>Do you agree to the statement: "Preact is awesome"?</p>
			<input value={input} onInput={e => setInput(e.target.value)} />
		</div>
	);
};

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

The exports map in package.json shows how far this split goes. Alongside the root entry there are separate subpaths for ./hooks, ./debug, ./devtools, ./test-utils, ./compat and ./compat/test-utils, each with its own type declarations under a src/index.d.ts file and its own built .mjs bundle. The repository layout mirrors this with top-level compat/, debug/, devtools/, hooks/, jsx-runtime/ and test-utils/ directories.

The practical effect is that the core you import stays small and you opt into extras. The cost is that an import of useState from 'preact' is wrong; it has to come from 'preact/hooks'. The example also uses onInput rather than onChange for the text field, which is worth noticing when you copy event handlers across from React code.

React compatibility lives behind the preact/compat alias, not in the core

Preact advertises extensive React compatibility, but it delivers that through preact/compat rather than through the main package. The mechanism is an alias: your build resolves imports of React to preact/compat, and third-party components written against React then run on Preact.

The compat layer has its own set of entry points in package.json. ./compat points at compat/dist/compat.mjs. ./compat/client offers both an import condition (compat/client.mjs) and a require condition (compat/client.js). ./compat/server goes further, with separate browser, import and require targets, and there is a dedicated ./compat/server.browser subpath.

What this means in practice: installing Preact by itself does not make React libraries work. Until the alias is configured in your bundler, any dependency that imports React will fail to resolve or pull in React itself, and you lose the size advantage you adopted Preact for. The project's wording is extensive compatibility, not complete compatibility, so a library that leans on React internals is not guaranteed to work. Test each dependency through the alias before committing a codebase to the switch.

The main entry is an ES module, and that shapes which toolchains can load it

The package.json for version 11.1.1 sets both main and module to dist/preact.mjs, and the default export condition for the root and for hooks, debug, devtools, test-utils and the JSX runtimes all point to .mjs files. Types come from the source tree: the root types condition is ./src/index.d.ts.

In the visible part of the exports map, only the compat client and server subpaths declare a require condition with a .js file. The core, hooks and debug entries list only types and default. If your project still loads dependencies through CommonJS require(), check how your runtime or bundler handles an .mjs default before upgrading, because the root entry point is an ES module file.

Browser support is stated as all modern browsers. The project makes no broader promise in that line, so if you ship to older browsers, you have to verify behaviour yourself.

For quick experiments without a build, the README links the unpkg URL for preact/dist/preact.mjs, which is the same file the main field references. The package is published to npm under the name preact with provenance enabled in publishConfig.

The advertised size is 3kB in one place and 4kB in another

Size is the reason most people look at Preact, and the project quotes it inconsistently. The GitHub repository description calls it a fast 3kB React alternative. The README tagline says fast 4kB alternative to React. The package.json description says Fast 4kb React-compatible Virtual DOM library.

None of these figures tells you what your bundle will weigh. They describe the core, while a real application imports at least preact/hooks, and a migration from React adds preact/compat on top. Debug and devtools entry points add more in development. Treat the number as a rough indication of the core's footprint and measure your own production bundle with the entry points you actually import.

The README badge row links preact/dist/preact.mjs on unpkg alongside the coveralls coverage report and a drydock diff page for the package. Those links describe the published core file, not the hooks, compat or debug bundles you add on top, so they cannot stand in for a measurement of your own build.

The 11.x line ships patch releases days apart

Preact is not archived, and the most recent push to the repository was on November 2, 2026. The release history shows a busy 11.x line: 11.0.2 on October 23, 2026, then 11.1.0 and 11.1.1 published on October 31, 2026, roughly twenty seconds apart. The package.json on the default branch, main, already reads 11.1.1.

Two releases on one morning means a minor version followed immediately by a patch, so pin to 11.1.1 rather than 11.1.0 if you are upgrading now, and read the release notes on GitHub for what changed between them.

For contributors, the repository uses pnpm (pnpm-lock.yaml and pnpm-workspace.yaml), Vitest for tests (vitest.config.mjs and vitest.setup.js), oxlint and oxfmt configuration files, and husky hooks. The demo/ folder is a useful reference for integration patterns: it contains examples for Redux, Redux Toolkit, MobX, context, fragments, nested Suspense, the profiler and devtools, plus files named key_bug.jsx and stateOrderBug.jsx that reproduce specific rendering cases. The project is MIT licensed, and the awesome-preact list collects third-party libraries built for it.

Editorial conclusion

Preact fits teams that want React's component, hooks and JSX model in a smaller package and are willing to configure a JSX pragma or jsx-runtime and alias React imports to preact/compat. It is a poor fit if you expect to drop it into an existing React codebase with no build changes. Before adopting it, check that every React library you depend on works through preact/compat, confirm your bundler resolves the .mjs entry points, and measure the bundle size yourself rather than trusting either the 3kB or 4kB figure.

Frequently asked questions

What is Preact?

Preact is an MIT-licensed JavaScript library for building user interfaces from components and a Virtual DOM. It offers the same modern API as React, including class components, function components and hooks, in a package described as 3kB to 4kB.

What is Preact vs React?

Preact keeps React's API and patterns but is a separate, smaller library. React libraries run on it through the preact/compat alias, and hooks are imported from preact/hooks rather than from the main package.

How to install Preact?

Preact is published to npm under the package name preact, currently at version 11.1.1. The built ES module is also served from unpkg at preact/dist/preact.mjs for use without a bundler.

How to use Preact?

Import h and render from preact, configure your compiler to use h for JSX (or use the jsx-runtime entry), and call render() with a component tree and a parent DOM element. Hooks such as useState come from preact/hooks.

Is Preact still relevant?

The repository is not archived, the last push was on November 2, 2026, and versions 11.0.2, 11.1.0 and 11.1.1 were all released in October 2026.

Official sources

  1. Official documentation
  2. Official README
  3. Project repository
  4. Release notes
Add this badge to your README

If you maintain this project, the badge below links readers to this analysis and shows its maintenance status from the daily GitHub snapshot. Paste the markdown into your README; add ?metric=license or ?metric=stars to the image URL for a different field.

Add this badge to your README

markdown
[![Hysen Labs](https://hysenlabs.com/badge/preactjs-preact.svg)](https://hysenlabs.com/projects/preactjs-preact)

Star history chart for your README

markdown
[![Star history](https://hysenlabs.com/chart/preactjs-preact.svg)](https://hysenlabs.com/projects/preactjs-preact)

Was this useful?