Components
- Use function components with typed props.
- Prefer
React.FConly when children typing is needed; otherwise avoid. - Memoize when beneficial (
React.memo,useMemo,useCallback).
Props & State
- Type props with interfaces or type aliases (PascalCase).
- Use
readonlyfor immutable props/state shapes. - Avoid
any; useunknownwhen necessary. - Prefer discriminated unions for state machines.
Hooks
- Extract logic into custom hooks.
- Type hook return values explicitly.
- Avoid unnecessary dependencies in hook arrays.
Data & Types
- Store a package's or folder's shared types in a
types.tsfile (e.g.domain/entity/contact/src/types.ts). - Declare the props of a component split into
X.web.tsxandX.native.tsxin the CODE2 contract ofuniversal-components. - Use Zod for runtime validation.
Imports & Exports
- Prefer named imports and named exports.
- Always declare imports at the beginning of source files.
- Import order:
1. External libs
2. Internal modules
3. Types
- Avoid default exports.
Packages read from source
Private packages have no build: a consumer compiles their src/ with its own compiler options, and
apps run them through per-file transpilers (SWC, Babel, rspack, Bun).
- A consumer must compile its dependencies' sources: it can be no stricter than them, and it needs the
settings their files require. When it cannot be, fix the dependency's source: the existing