Skip to content

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
Step-by-step guide: how to use PreactInstall, first run, examples, tips and FAQs

How to get it

  1. 1

    Install with a package manager

    You'll need: Node.js (version not specified in the README)

    Install from npm

    npm install preact
  2. 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. 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

ProjectStarsTypeLevelUpdatedBest for
preact (this)39kLibraryintermediate4 days agoWeb developers who already know React and want a lighter library
react252kLibraryintermediate6 days agoDevelopers building interactive web interfaces with JavaScript
inferno16.5kLibraryintermediate6 days agoDevelopers already familiar with React who want a React-like API
vue212kLibraryintermediate2.1 years agoMaintaining an existing Vue 2 application that cannot yet be upgraded
million17.7kLibraryintermediate6 months agoReact developers whose apps have many elements that update often
mithril.js14.5kLibraryintermediate3 months agoDevelopers 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.