Preact is a lightweight, 3KB JavaScript library offering a React-compatible API for building user interfaces with a Virtual DOM. Currently in its stable v10.29.1 series, it maintains a rapid release cadence with frequent patch and minor updates, alongside public betas for upcoming major versions like 11.0.0-beta.1. Key differentiators include its extremely small footprint, which is beneficial for performance and bundle size, while largely replicating the modern React API including hooks, functional components, and class components. It offers extensive compatibility with the React ecosystem through its `preact/compat` alias, enabling many existing React libraries to function with minimal configuration. Preact features an optimized diffing algorithm, supports Server-Side Rendering (SSR), and includes developer tools and Hot Module Replacement (HMR) capabilities. It targets all modern browsers and maintains compatibility with IE11, providing a robust yet minimal alternative for web development.
npm install preactVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to create and render a basic functional Preact component using JSX, including an initial mount and an in-place update to the DOM.
Install `preact/compat` and configure your bundler to alias `react` and `react-dom` to `preact/compat`. Example for Webpack: `resolve.alias: { 'react': 'preact/compat', 'react-dom/test-utils': 'preact/compat/test-utils', 'react-dom': 'preact/compat' }`For TypeScript, add `"jsxFactory": "h"` to `compilerOptions` in `tsconfig.json`. For Babel, configure `@babel/plugin-transform-react-jsx` with `"pragma": "h"`. Alternatively, add `/** @jsx h */` at the top of each JSX/TSX file.
Ensure your project's `package.json` includes `"type": "module"` if running directly in Node.js, or use a bundler (Webpack, Rollup, Vite) that correctly transpiles and resolves ES Modules for browser environments. Always prefer `import` statements.
Consult the official Preact v11 migration guide upon its stable release. Thoroughly test your application when upgrading from v10 to v11.
Configure your `tsconfig.json` (`jsxFactory: "h"`) or Babel config (`@babel/plugin-transform-react-jsx` with `pragma: 'h'`) to use Preact's `h` function for JSX, or add `/** @jsx h */` to your files.
Ensure your project's `package.json` has `"type": "module"` for Node.js environments, or use a bundler (Webpack, Rollup, Vite) that handles ES module compilation for browser code.
Install `preact/compat` and configure your bundler (e.g., Webpack, Rollup) to alias `react` and `react-dom` imports to `preact/compat`.
Ensure all hook calls are made directly within the top level of a functional component or a custom hook, and not inside loops, conditions, or nested functions.
No dependency data recorded yet.