
Preact
A small (about 4kB) React-style library for building user interfaces in JavaScript.
- Stars
- 39k
- Forks
- 3.2k
- Licence
- MIT
- Language
- JavaScript
- Last update
- 4 days ago
- Type
- Library
What it is
Preact is a JavaScript library for building user interfaces out of reusable components, using an API that closely follows React. The README describes it as a fast, roughly 4kB alternative to React with a similar modern API, covering components, hooks, JSX, and a virtual DOM. Developers use it when they want React-style code with a much smaller download size.
- Build interactive web page components with function components and hooks
- Render a UI on the server and hydrate it in the browser using the built-in SSR support
- Write components in JSX or HTM (tagged templates) without a build step, as shown in the README's tagline on syntax choices
- Migrate an existing React codebase gradually by aliasing react to preact/compat
Great for
- Web developers who already know React and want a lighter library
- Projects where small bundle size matters, such as pages loaded over slow connections
- Teams that want an optional compatibility alias (preact/compat) to reuse React-based code
- Developers building apps that need server-side rendering with hydration
Not ideal for
- Complete beginners who have never written JavaScript; the README assumes familiarity with components and modern JS syntax
- Projects that depend on React-only libraries without testing compatibility, since the README only describes compatibility as 'extensive' via an alias and does not list limits
- Native mobile app development, which the README does not mention
How to get it
- 1
Install with a package manager
You'll need: Node.js (version not specified in the README)
Install from npm
npm install preact - 2
Run it
- Install Preact with npm install preact
- Import render and h from 'preact' in a JavaScript file and configure JSX to use h
- Call render(<App />, document.body) to display your first component
- Use useState from 'preact/hooks' to add interactive state
- 3
Get the most out of it
- Use the preact/compat alias to run React-based libraries on Preact
- Use HTM with tagged templates if you want to avoid a JSX build step
- Read the Preact website for DevTools, HMR, and SSR setup guidance
Downloads
Strengths
- Very small size (the README states about 4kB), which helps page load time
- Familiar React API, including class components, hooks, and functional components
- MIT licensed with a large community and many stars on GitHub
Trade-offs
- The README is truncated and gives limited detail on edge-case React compatibility
- Some React ecosystem libraries may need the compat layer or may not work fully
- Tooling such as DevTools and HMR depends on additional setup that the README only briefly mentions
How it compares
| Project | Stars | Type | Level | Updated | Best for |
|---|---|---|---|---|---|
| preact (this) | 39k | Library | intermediate | 4 days ago | Web developers who already know React and want a lighter library |
| react | 252k | Library | intermediate | 5 days ago | Developers building interactive web interfaces with JavaScript |
| inferno | 16.5k | Library | intermediate | 6 days ago | Developers already familiar with React who want a React-like API |
| vue | 212k | Library | intermediate | 2.1 years ago | Maintaining an existing Vue 2 application that cannot yet be upgraded |
| million | 17.7k | Library | intermediate | 6 months ago | React developers whose apps have many elements that update often |
| mithril.js | 14.5k | Library | intermediate | 3 months ago | Developers who want a small framework with routing and HTTP utilities included |
Stats synced from GitHub. The assessment above was drafted with AI from the project's README on 2026-10-29 and may miss recent changes — check the README before relying on a command. MIT licence: free to use, modify and distribute, including commercially, as long as you keep the copyright notice.