preact
⚛️ Fast 3kB React alternative with the same modern API. Components & Virtual DOM.
Preact is a 4-kilobyte JavaScript library with the same API as React, components, hooks, and JSX, but loads far faster, making it ideal for websites and apps where bundle size and page speed matter.
Preact is a lightweight JavaScript library for building user interfaces, designed as a minimal alternative to React. It offers the same core API as React — components, hooks, JSX syntax, and a virtual DOM — but in a package that weighs roughly 4 kilobytes when compressed, compared to React's much larger footprint. The goal is to give developers the familiar React programming model without the overhead, making it especially well-suited for performance-critical applications or contexts where bundle size matters.
Preact works by maintaining a virtual DOM — an in-memory description of what the UI should look like — and then calculating the minimum number of real DOM changes needed whenever something updates. This diffing process is highly optimized. You write components the same way you would in React: as functions or classes that return JSX, using hooks like useState and useEffect for managing state and side effects. A compatibility layer called preact/compat allows most existing React libraries and code to run on Preact without modification, just by aliasing the import. Preact also supports server-side rendering, hot module replacement for development, and browser DevTools integration.
You would reach for Preact when you need the React development experience but are building for an environment where JavaScript bundle size is a significant concern — for example, performance-focused websites, embedded widgets, or apps targeting slow network connections. It is also a natural choice if you are already comfortable with React but want a leaner dependency. The tech stack is JavaScript and TypeScript, running in any modern browser environment. It has no required build tool and works with standard module bundlers.
Where it fits
- Replace React in a performance-sensitive website to cut your JavaScript bundle by over 90% with no API changes.
- Build lightweight embedded widgets or single-page apps where a full React download would hurt load times.
- Run existing React libraries on Preact without code changes by aliasing imports through the preact/compat layer.