How to understand a Preact codebase
Preact is a small library with React's component API. Many Preact apps use React libraries through `preact/compat`, which the build aliases in place of `react`. Some use `@preact/signals` for state, which updates the DOM without re-rendering whole components.
How to tell it's Preact
preactinpackage.json, often with@preact/preset-vite- Imports from
preact,preact/hooksorpreact/compat - Aliases mapping
reactandreact-domtopreact/compatin the bundler config
Where things usually live
- src/index.tsx or main.tsx
- Calls
render(<App />, element). - src/components/
- Function components using hooks from
preact/hooks. - src/state/ or signals.ts
- Signals created with
signal()andcomputed(). - vite.config.ts
- The Preact preset and any
reactaliases.
Conventions, not rules. Real projects rename and move things, so confirm against the repository.
Where to start reading
- The
rendercall, to see the root component - The bundler config, to check whether React libraries are aliased
- Any signals module, for shared state
How a request moves through the code
rendermounts the root component.- Components use hooks for local state, or read signals for shared state.
- Reading
signal.valueinside JSX subscribes that spot; updating it patches the DOM directly. - React libraries run through
preact/compat.
Questions to ask about the repository
- Which React libraries does this app depend on through
preact/compat? - Where are signals defined, and which components read them?
- Is any code relying on React-only behaviour that compat may not cover?
What trips people up
- Some React libraries depend on React internals and break subtly under compat.
- Preact passes DOM attributes more directly than React, so
classandclassNamemay both appear.