preactjs/preact

JavaScriptpreactjs.com

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

preactjsxreactvirtual-domcomponentsdomvdom
Crescimento de estrelas
Estrelas
38.9k
Forks
2.1k
Crescimento semanal
+8
Issues
19
10k20k30k
mai. de 2019out. de 2021mar. de 2024set. de 2026
Artefatosnpm
README

Preact

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 ➞

npm Preact Slack Community OpenCollective Backers OpenCollective Sponsors

coveralls gzip size brotli size

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.

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:

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

/** @jsx h */

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

	return (
		<div>
			<p>Do you agree to the statement: "Preact is awesome"?</p>
			<input value={input} onInput={e => setInput(e.target.value)} />
		</div>
	);
};

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]

            SentDM Songsterr Deno

Backers

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


License

MIT

Preact

Repositórios relacionados
aidenybai/million

Optimizing compiler for React

TypeScriptnpmtutorialMIT Licensehacktoberfestmillion
old.million.dev
17.7k595
freshframework/fresh

The framework so simple, you already know it.

TypeScriptnpmlibraryMIT Licensedenofresh
usefresh.dev
13.8k754
codesandbox/codesandbox-client

An online IDE for rapid web development

JavaScriptnpmOthercodesandboxreact
codesandbox.io
13.6k2.4k
jaredpalmer/razzle

✨ Create server-rendered universal JavaScript applications with no configuration

JavaScriptnpmMIT Licenseisomorphicuniversal
razzlejs.org
11k841
molefrog/wouter

🥢 A minimalist-friendly ~2.2KB routing for React and Preact

TypeScriptnpmThe Unlicensereact-hooksrouter
npm.im/wouter
7.9k189
gitalk/gitalk

Gitalk is a modern comment component based on Github Issue and Preact.

JavaScriptnpmMIT Licensecommentplugin
gitalk.github.io
7.2k617
insin/nwb

A toolkit for React, Preact, Inferno & vanilla JS apps, React libraries and other npm modules for the web, with no configuration (until you need it)

JavaScriptnpmOthertoolkitreact
5.5k319
NervJS/nerv

A blazing fast React alternative, compatible with IE8 and React 16.

JavaScriptnpmlibraryMIT Licensenervreact
nerv.aotu.io
5.4k262
egoist/poi

⚡A zero-config bundler for JavaScript applications.

JavaScriptnpmlibraryMIT Licensewebpackbuild-tool
poi.js.org
5.2k252
extension-js/extension.js

The cross-browser extension framework.

TypeScriptnpmcliMIT Licensewebextensionbrowser-extension
extension.js.org
5.1k137
preactjs/wmr

👩‍🚀 The tiny all-in-one development tool for modern web apps.

JavaScriptnpmlibraryMIT Licensebuild-toolesmodules
wmr.dev
4.9k105
transitive-bullshit/create-react-library

CLI for creating reusable react libraries.

JavaScriptnpmclireactlibrary
transitivebullsh.it/javascript-dev-tools-in-2022
4.8k290