Skip to content

React Compatibility

Tachys provides a compatibility layer at tachys/compat that mirrors the React API, allowing you to use React-ecosystem libraries.

Setup

Vite

ts
// vite.config.ts
import { defineConfig } from "vite"

export default defineConfig({
  resolve: {
    alias: {
      react: "tachys/compat",
      "react-dom": "tachys/compat",
      "react-dom/client": "tachys/client",
      "react-dom/server": "tachys/server",
    },
  },
  esbuild: {
    jsxImportSource: "tachys",
  },
})

Webpack

js
// webpack.config.js
module.exports = {
  resolve: {
    alias: {
      react: "tachys/compat",
      "react-dom": "tachys/compat",
      "react-dom/client": "tachys/client",
      "react-dom/server": "tachys/server",
    },
  },
}

What's Included

The compat module re-exports the full core API plus React-specific names:

React APITachys equivalent
createElementh
Fragmentnull (fragment sentinel)
All hooks (useState, useEffect, etc.)Direct re-exports
useSyncExternalStoreDirect re-export (with tearing prevention)
useDirect re-export (React 19 Promises + Context)
useTransition, startTransitionDirect re-exports (lane-based scheduling)
useDeferredValueDirect re-export (lane-based scheduling)
memo, forwardRef, createRef, createContextDirect re-exports
Suspense, lazy, ErrorBoundaryDirect re-exports
render, createPortalDirect re-exports
createRoot, hydrateRootDirect re-exports (React 18 root API)
flushSyncflushUpdates
Children.map/forEach/count/only/toArrayBuilt-in utilities
cloneElementClones VNode with merged props
isValidElementChecks if value is a VNode
Component / PureComponentStubs (throws if instantiated)
StrictModeNo-op passthrough
ProfilerNo-op passthrough
actTesting utility (flushes sync/async updates)
useOptimisticOptimistic UI state (React 19)
useActionStateForm action reducer (React 19)
useFormStatusForm status (always idle)
preload, preloadModule, preinit, preinitModuleInject <link> / <script> into <head> (React 19)
preconnect, prefetchDNSInject <link rel=preconnect> / <link rel=dns-prefetch> (React 19)

Limitations

  • Class components are not supported. Component and PureComponent are exported as stubs that throw if instantiated. Use functional components instead.
  • Synthetic events are not wrapped. Event handlers receive native DOM events directly. Most React code works fine since the native API is a superset.
  • findDOMNode is not provided. Use refs instead.
  • String refs are not supported. Use createRef() or callback refs.

Dual-licensed under MIT or Apache-2.0.