This template is for building a reusable React TypeScript library: components + hooks + utils.
Tooling is standardized — do not change it casually.
-
src/components/
React UI components only. -
src/hooks/
React hooks only (state/side-effects/live integrations). -
src/utils/
Framework-agnostic utilities (no React imports). -
src/__tests___Unit tests directory -
src/index.ts
The only public API entrypoint.
-
Consumers must import from the package root only:
- ✅
import { X } from "@scope/pkg" - ❌
import { X } from "@scope/pkg/dist/..." - ❌
import { X } from "@scope/pkg/src/..."
- ✅
-
Only export public things from
src/index.ts. -
Anything not exported from
src/index.tsis private and may change freely.
- MUST NOT import
reactorreact-dom. - No DOM globals unless explicitly required.
- Pure functions preferred.
- May import React.
- Avoid “magic” side effects: prefer explicit params.
- No direct network calls unless the library is explicitly meant to do so.
- May import React.
- Keep UI behavior self-contained and testable.
- No styling dependencies.
- Tailwind-compatible className patterns are allowed
- Do not assume global CSS
- Do not ship Tailwind as a dependency
Default pattern:
src/components/Button/Button.tsxsrc/components/Button/index.tsexports Buttonsrc/components/index.tsre-exports all componentssrc/index.tsre-exportscomponents,hooks,utils
- Vitest only.
- Prefer unit tests for
utils. - For
components/hooks, start with behavior tests and keep DOM coupling minimal.