Preact — Fast 3kB React Alternative with Same Modern API
Preact is a fast 3kB alternative to React with the same modern API. Virtual DOM, Components, Hooks — all in a tiny package. Drop-in compatible via preact/compat. Perfect for performance-critical apps and islands architecture.
What it is
Preact is a fast 3kB alternative to React that provides the same modern API: Virtual DOM, functional components, hooks, and context. It achieves this by focusing on the core rendering engine and dropping rarely-used features. For full React compatibility, preact/compat provides a drop-in layer that works with most React libraries.
Preact targets developers building performance-critical web applications where bundle size matters. It is ideal for widgets, embedded UIs, progressive web apps, and any project where loading speed is a priority.
How it saves time or tokens
Preact's 3kB gzip size means faster page loads, especially on mobile networks and low-powered devices. The React-compatible API means you do not need to learn a new framework; existing React knowledge transfers directly. preact/compat lets you use React ecosystem libraries (React Router, React Query, etc.) without modifications. Migration from React to Preact is often a matter of aliasing imports.
How to use
- Create a new Preact project:
npm init preact
- Or add Preact to an existing project:
npm install preact
- Write components using familiar React patterns:
import { render } from 'preact';
import { useState } from 'preact/hooks';
function Counter() {
const [count, setCount] = useState(0);
return (
<button onClick={() => setCount(count + 1)}>
Count: {count}
</button>
);
}
render(<Counter />, document.getElementById('app'));
Example
// Using preact/compat for React library compatibility
// vite.config.ts
import { defineConfig } from 'vite';
export default defineConfig({
resolve: {
alias: {
'react': 'preact/compat',
'react-dom': 'preact/compat',
'react/jsx-runtime': 'preact/jsx-runtime'
}
}
});
// Now React libraries work with Preact
import { useQuery } from '@tanstack/react-query';
import { BrowserRouter, Route } from 'react-router-dom';
Related on TokRepo
- AI Tools for Coding — Developer tools and frameworks
- Featured Workflows — Top-rated development tools
This tool integrates with standard development workflows and requires minimal configuration to get started. It is available as open-source software with documentation and community support through the official repository. The project follows semantic versioning for stable releases.
For teams evaluating this tool, the key advantage is reducing manual work in repetitive tasks. The automation provided by the built-in features means less custom code to maintain and fewer integration points to manage. This translates directly to lower maintenance costs and faster iteration cycles.
Common pitfalls
- Not all React libraries work with
preact/compat; libraries that rely on React internals or concurrent mode features may break. Test compatibility before committing to a migration. - Preact's event system has minor differences from React (e.g., synthetic events); most code works unchanged, but edge cases in event handling may surface.
- The 3kB size applies to Preact core; adding
preact/compatincreases the bundle, though it remains smaller than React.
Frequently Asked Questions
Yes, via preact/compat. It provides a compatibility layer that aliases React imports to Preact equivalents. Most React libraries work without modification, including React Router, React Query, and Material UI.
Preact is generally faster for initial page load due to its smaller bundle size (3kB vs ~40kB for React). Runtime rendering performance is comparable for most applications. The difference is most noticeable on slow networks and low-powered devices.
Yes. For many projects, migration involves aliasing react and react-dom to preact/compat in your bundler configuration. No code changes are needed if your components use standard React APIs.
Yes. Preact supports useState, useEffect, useContext, useReducer, useMemo, useCallback, useRef, and all other standard hooks. Import them from preact/hooks.
Yes. Preact is used in production by companies of all sizes. It has been actively maintained since 2015 and has a stable API. The core team provides regular releases and security updates.
Citations (3)
- Preact Official Site— Preact is a fast 3kB alternative to React with the same API
- Preact GitHub— preact/compat provides drop-in React compatibility
- Preact Documentation— Preact supports hooks, context, and functional components
Related on TokRepo
Discussion
Related Assets
Moodle — Open-Source Learning Management System
The most widely used open-source learning platform, providing course management, assessments, and collaboration tools for educators and organizations worldwide.
Sylius — Headless E-Commerce Framework on Symfony
An open-source headless e-commerce platform built on Symfony and API Platform, designed for developers who need a customizable and API-first commerce solution.
Akaunting — Free Self-Hosted Accounting Software
A free, open-source online accounting application built on Laravel for small businesses and freelancers to manage invoices, expenses, and financial reports.