preact

WebJar for preact

License

License

MIT
Categories

Categories

Github Development Tools Version Controls React User Interface Web Frameworks
GroupId

GroupId

org.webjars.npm
ArtifactId

ArtifactId

github-com-developit-preact
Last Version

Last Version

6.0.2
Release Date

Release Date

Type

Type

jar
Description

Description

preact
WebJar for preact
Project URL

Project URL

http://webjars.org
Source Code Management

Source Code Management

https://github.com/developit/preact

Download github-com-developit-preact

How to add to project

<!-- https://jarcasting.com/artifacts/org.webjars.npm/github-com-developit-preact/ -->
<dependency>
    <groupId>org.webjars.npm</groupId>
    <artifactId>github-com-developit-preact</artifactId>
    <version>6.0.2</version>
</dependency>
// https://jarcasting.com/artifacts/org.webjars.npm/github-com-developit-preact/
implementation 'org.webjars.npm:github-com-developit-preact:6.0.2'
// https://jarcasting.com/artifacts/org.webjars.npm/github-com-developit-preact/
implementation ("org.webjars.npm:github-com-developit-preact:6.0.2")
'org.webjars.npm:github-com-developit-preact:jar:6.0.2'
<dependency org="org.webjars.npm" name="github-com-developit-preact" rev="6.0.2">
  <artifact name="github-com-developit-preact" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.webjars.npm', module='github-com-developit-preact', version='6.0.2')
)
libraryDependencies += "org.webjars.npm" % "github-com-developit-preact" % "6.0.2"
[org.webjars.npm/github-com-developit-preact "6.0.2"]

Dependencies

There are no dependencies for this project. It is a standalone project that does not depend on any other jars.

Project Modules

There are no modules declared in this project.

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
  • Instant production-grade app setup with Preact CLI

๐Ÿ’ 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 ๐Ÿ˜Ž


Getting Started

๐Ÿ’ Note: You don't need ES2015 to use Preact... but give it a try!

The easiest way to get started with Preact is to install Preact CLI. This simple command-line tool wraps up the best possible tooling for you, and even keeps things like Webpack and Babel up-to-date as they change. Best of all, it's easy to understand! Start a project or compile for production in a single command (preact build), with no configuration needed and best practices baked in! ๐Ÿ™Œ

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} onChange={e => setInput(e.target.value)} />
		</div>
	)
}

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

Backers

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

Sponsors

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


License

MIT

Preact

Versions

Version
6.0.2