preact/compat is a compatibility layer that allows you to use React libraries and components with Preact. It provides a React-compatible API surface, making it possible to leverage the vast React ecosystem while benefiting from Preact’s small size and performance.
preact/compat adds approximately 2-3kb to your bundle size, keeping Preact significantly smaller than React while maintaining compatibility.
preact/compat supports multiple import paths for React compatibility:
// Main compat layerimport React from 'preact/compat';// React DOMimport ReactDOM from 'preact/compat';// React DOM Client (React 18)import { createRoot, hydrateRoot } from 'preact/compat/client';// React DOM Serverimport { renderToString, renderToStaticMarkup } from 'preact/compat/server';// JSX Runtimeimport { jsx, jsxs } from 'preact/jsx-runtime';// Schedulerimport * as Scheduler from 'preact/compat/scheduler';// Test utilitiesimport { act } from 'preact/compat/test-utils';
While preact/compat provides excellent React compatibility, some edge cases and library-specific behaviors may differ. See the Differences page for details.