Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/preactjs/preact
⚛️ Fast 3kB React alternative with the same modern API. Components & Virtual DOM.
https://github.com/preactjs/preact
components dom jsx preact react vdom virtual-dom
Last synced: 3 days ago
JSON representation
⚛️ Fast 3kB React alternative with the same modern API. Components & Virtual DOM.
- Host: GitHub
- URL: https://github.com/preactjs/preact
- Owner: preactjs
- License: mit
- Created: 2015-09-11T02:40:18.000Z (over 9 years ago)
- Default Branch: main
- Last Pushed: 2024-12-04T15:37:58.000Z (8 days ago)
- Last Synced: 2024-12-06T09:04:10.454Z (6 days ago)
- Topics: components, dom, jsx, preact, react, vdom, virtual-dom
- Language: JavaScript
- Homepage: https://preactjs.com
- Size: 16.4 MB
- Stars: 36,916
- Watchers: 397
- Forks: 1,953
- Open Issues: 154
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- Funding: .github/FUNDING.yml
- License: LICENSE
- Code of conduct: .github/CODE_OF_CONDUCT.md
Awesome Lists containing this project
- awesome-frontend - preact - Fast 3kB React alternative with the same modern API. Components & Virtual DOM. ![](https://img.shields.io/github/stars/preactjs/preact.svg?style=social&label=Star) (Repository / JavaScript Framework)
- stars - preactjs/preact
- awesome - preact - ⚛️ Fast 3kB React alternative with the same modern API. Components & Virtual DOM. (JavaScript)
- awesome-game-engine-dev - Preact - Fast 3kB React alternative with the same modern API. (Libraries / JavaScript)
- awesome-starred-test - preactjs/preact - ⚛️ Fast 3kB React alternative with the same modern API. Components & Virtual DOM. (JavaScript)
- awesome-tiny-js - preact - React-like API (pre-hooks). Cool ecosystem of similarly tiny tools and components. Highly recommended. <img align="top" height="24" src="./img/preact.svg"> (UI Frameworks)
- awesome-repositories - preactjs/preact - ⚛️ Fast 3kB React alternative with the same modern API. Components & Virtual DOM. (JavaScript)
- awesome-github-star - preact
- awesome-list - preact
- best-of-react - GitHub - 11% open · ⏱️ 02.06.2024): (Others)
- StarryDivineSky - preactjs/preact
- awesome-react-cn - preact
- awesome-react - preact - Fast React alternative with the same modern API (**Awesome React** [![Awesome](https://cdn.rawgit.com/sindresorhus/awesome/d7305f38d29fed78fa85652e3a63e154dd8e8829/media/badge.svg)](https://github.com/sindresorhus/awesome) / React)
README
![Preact](https://raw.githubusercontent.com/preactjs/preact/8b0bcc927995c188eca83cba30fbc83491cc0b2f/logo.svg?sanitize=true 'Preact')
Fast 3kB 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 and IE11
- Transparent asynchronous rendering with a pluggable scheduler### 💁 More information at the [Preact Website ➞](https://preactjs.com)
[![npm](https://img.shields.io/npm/v/preact.svg)](http://npm.im/preact)
[![Preact Slack Community](https://img.shields.io/badge/Slack%20Community-preact.slack.com-blue)](https://chat.preactjs.com)
[![OpenCollective Backers](https://opencollective.com/preact/backers/badge.svg)](#backers)
[![OpenCollective Sponsors](https://opencollective.com/preact/sponsors/badge.svg)](#sponsors)[![coveralls](https://img.shields.io/coveralls/preactjs/preact/main.svg)](https://coveralls.io/github/preactjs/preact)
[![gzip size](http://img.badgesize.io/https://unpkg.com/preact/dist/preact.min.js?compression=gzip&label=gzip)](https://unpkg.com/preact/dist/preact.min.js)
[![brotli size](http://img.badgesize.io/https://unpkg.com/preact/dist/preact.min.js?compression=brotli&label=brotli)](https://unpkg.com/preact/dist/preact.min.js)You can find some awesome libraries in the [awesome-preact list](https://github.com/preactjs/awesome-preact) :sunglasses:
---
## Getting Started
> 💁 _**Note:** You [don't need ES2015 to use Preact](https://github.com/developit/preact-in-es3)... 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](https://facebook.github.io/jsx/) (shown underneath), or [HTM](https://github.com/developit/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.
```js
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(
Hello
,
document.body
);// update the tree in-place:
render(
Hello World!
,
document.body
);
// ^ this second invocation of render(...) will use a single DOM call to update the text of the
```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:
```js
import { render, h } from 'preact';
import { useState } from 'preact/hooks';/** @jsx h */
const App = () => {
const [input, setInput] = useState('');return (
Do you agree to the statement: "Preact is awesome"?
setInput(e.target.value)} />
);
};render(, document.body);
```---
## Sponsors
Become a sponsor and get your logo on our README on GitHub with a link to your site. [[Become a sponsor](https://opencollective.com/preact#sponsor)]
## Backers
Support us with a monthly donation and help us continue our activities. [[Become a backer](https://opencollective.com/preact#backer)]
---
## License
MIT
[![Preact](https://i.imgur.com/YqCHvEW.gif)](https://preactjs.com)
[preact/compat]: https://github.com/preactjs/preact/tree/main/compat
[hyperscript]: https://github.com/dominictarr/hyperscript
[DevTools]: https://github.com/preactjs/preact-devtools