Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
P

preact

> 前端框架
Open source

⚛️ Fast 3kB React alternative with the same modern API. Components & Virtual DOM.

38.8K stars0 likes4 views
WebsiteGitHub

About

⚛️ Fast 3kB React alternative with the same modern API. Components & Virtual DOM.

Fast 4kB alternative to React with the same modern API.

All the power of Virtual DOM components, without the overhead:

  • Familiar React API & patterns: ES6 Class, hooks, and Functional Components
  • Extensive React compatibility via a simple [preact/compat] alias
  • Everything you need: JSX, VDOM, [DevTools], HMR, SSR.
  • Highly optimized diff algorithm and seamless hydration from Server Side Rendering
  • Supports all modern browsers
  • Transparent asynchronous rendering with a pluggable scheduler

💁 More information at the Preact Website ➞

You can find some awesome libraries in the awesome-preact list :sunglasses:


Getting Started

💁 Note: You don't need ES2015 to use Preact... but give it a try!

Tutorial: Building UI with Preact

With Preact, you create user interfaces by assembling trees of components and elements. Components are functions or classes that return a description of what their tree should output. These descriptions are typically written in JSX (shown underneath), or HTM which leverages standard JavaScript Tagged Templates. Both syntaxes can express trees of elements with "props" (similar to HTML attributes) and children.

To get started using Preact, first look at the render() function. This function accepts a tree description and creates the structure described. Next, it appends this structure to a parent DOM element provided as the second argument. Future calls to render() will reuse the existing tree and update it in-place in the DOM. Internally, render() will calculate the difference from previous outputted structures in an attempt to perform as few DOM operations as possible.

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

Hooray! render() has taken our structure and output a User Interface! This approach demonstrates a simple case, but would be difficult to use as an application grows in complexity. Each change would be forced to calculate the difference between the current and updated structure for the entire application. Components can help here – by dividing the User Interface into nested Components each can calculate their difference from their mounted point. Here's an example:

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

/** @jsx h */

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

	return (
		

	);
};

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

Sponsors

Become a sponsor and get your logo on our README on GitHub with a link to your site. [Become a sponsor]

           

Backers

Support us with a monthly donation and help us continue our activities. [Become a backer]


License

MIT [preact/compat]: https://github.com/preactjs/preact/tree/main/compat [hyperscript]: https://github.com/dominictarr/hyperscript [DevTools]: https://github.com/preactjs/preact-devtools

Issues· 49 open

View all issuesOpen on GitHub
  • #5287

    Ref cleanup runs twice or for the wrong element when a callback ref is reused

    Updated Sep 29, 2026
  • #5264

    Uncaught render error permanently drops the other components queued in the same pass

    Updated Sep 24, 2026
  • #5261

    Support `REACT_RECOVERABLE_TYPE` in `use`

    feature requestUpdated Sep 22, 2026
  • #2621

    The road to Preact 11

    discussionUpdated Aug 23, 2026
  • #5177

    different behaviors between Preact and React in Mui-x date pickers

    Updated Aug 6, 2026
  • #678

    Checking `prop in elem` fails with deferred custom element definitions

    Updated Aug 5, 2026
  • #4977

    Add compatibility with React 19 <Activity />

    feature requestUpdated Jul 31, 2026
  • #3666

    [preact/compat] radix-ui Slider component drag points (Thumbs) not working

    compatUpdated Mar 24, 2026
  • #2618

    App statistics: Help us make Preact even faster

    Updated Mar 18, 2026
  • #4994

    JSX types reflect core + compat, when compat may or may not be used

    typesfeature requestUpdated Jan 10, 2026

> Tags

JavaScriptcomponentsdomjsxpreact

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 30, 2026
Category前端框架
PricingOpen source

> Related tools

R
React
用于构建用户界面的 JavaScript 库
V
Vue.js
渐进式 JavaScript 框架
N
Next.js
基于 React 的全栈 Web 框架