This file provides context for AI agents (Cursor, Claude, Copilot, etc.) working on this repository. Read it in full before making any changes.
react-native-typescript-library-starter is a React Native TypeScript library starter template. It is NOT an application β it is a publishable npm package used as a starting point for building React Native component/hook libraries.
- Build tool:
react-native-builder-bob(outputs CJS + ESM + TypeScript declarations) - Testing: Jest +
@testing-library/react-native - Language: TypeScript (strict mode, no
any) - Linting: ESLint v8 + Prettier
- CI: GitHub Actions (typecheck + lint + test + build)
react-native-typescript-library-starter/
βββ src/ # ALL library source code lives here
β βββ index.ts # Public API β only export from here
β βββ components/
β β βββ MyComponent/
β β βββ MyComponent.tsx # Implementation
β β βββ MyComponent.types.ts # Props interface
β β βββ index.ts # Barrel export
β βββ hooks/
β β βββ useMyHook.ts # Custom hook with TSDoc
β βββ types/
β β βββ index.ts # Shared utility types
β βββ __tests__/
β βββ MyComponent.test.tsx
β βββ useMyHook.test.ts
βββ lib/ # GENERATED by bob β do NOT edit manually
β βββ commonjs/ # CJS output
β βββ module/ # ESM output
β βββ typescript/ # .d.ts declarations
βββ scripts/
β βββ terminal/
β βββ lint.mjs # Colored ESLint runner
β βββ prettier.mjs # Colored Prettier runner
βββ .github/
β βββ workflows/
β βββ ci.yml # Runs on PR: typecheck + lint + test + build
β βββ release.yml # Runs on push to main: release pipeline
βββ .husky/ # Git hooks (pre-commit, commit-msg)
βββ AGENTS.md # This file
βββ CONTRIBUTING.md
βββ CHANGELOG.md
βββ README.md
βββ package.json # bob config, jest config, lint-staged config
βββ tsconfig.json # Base TypeScript config
βββ tsconfig.build.json # bob-specific build config
βββ babel.config.js # metro-react-native-babel-preset (for Jest)
βββ .eslintrc.js
βββ .prettierrc
βββ .commitlintrc.json
All commands should be run from the repository root.
| Command | Description |
|---|---|
npm run setup |
Interactive wizard β configure name, author, repo URLs |
npm install |
Install all dependencies (also runs husky via prepare) |
npm run build |
Build library to lib/ via bob |
npm run typecheck |
Type-check without emitting files |
npm run lint |
Run ESLint with colored output |
npm run lint:ci |
Run ESLint without spinner (for CI) |
npm run prettier |
Format code with colored output |
npm run prettier:ci |
Check formatting without spinner (for CI) |
npm test |
Run Jest tests |
npm run test:watch |
Run Jest in watch mode |
npm run test:coverage |
Run Jest with coverage report |
- Strict mode is enabled (
"strict": true). Noany, nots-ignorewithout a comment explaining why. - Use
typefor type aliases andinterfacefor object shapes. - Always use
import typefor type-only imports. - Path alias
@/*maps tosrc/*.
- One component per folder under
src/components/. - File naming:
MyComponent.tsx(implementation),MyComponent.types.ts(props),index.ts(barrel). - Props interface must be named
<ComponentName>Propsand exported from the barrel. - All props must have TSDoc comments with
@exampletags for non-trivial props. - Use
StyleSheet.create()β no inline style objects. - Forward
testIDand derive child testIDs as${testID}-<part>.
- One hook per file under
src/hooks/. - Export the hook as a named export (not default).
- Export the options interface as
Use<HookName>Options. - Export the return interface as
Use<HookName>Return. - All hooks must have full TSDoc with
@param,@returns, and@example.
- Only add exports to
src/index.tsβ this is the package entry point. - Export both the value and its types from
src/index.ts. - Never import from
lib/β always fromsrc/.
Follow Conventional Commits. Allowed types: feat, fix, perf, refactor, style, test, docs, ci, chore, revert.
Examples:
feat: add PressableCard component
fix: correct button accessibility role
test: add edge cases for useMyHook
docs: update README with new API
- Test files live in
src/__tests__/. - File names match the source:
MyComponent.test.tsx,useMyHook.test.ts. - Use
@testing-library/react-nativefor component tests (render,fireEvent,getByTestId). - Use
renderHook+actfor hook tests. - Group tests with
describeblocks:describe("rendering"),describe("interactions"),describe("accessibility"). - Coverage thresholds: 70% branches, 80% functions/lines/statements.
- Do NOT edit files in
lib/β they are generated bybob build. - Do NOT use
require()β use ES moduleimport. - Do NOT add
peerDependenciesasdependenciesordevDependencieswithout justification. - Do NOT export internal helpers from
src/index.tsβ only public API. - Do NOT disable ESLint rules without an explanatory comment.
- Do NOT add
console.logto source files. - Do NOT use default exports for hooks β named exports only.
- Do NOT skip tests when adding new features.
- Create
src/components/NewComponent/NewComponent.types.tsβ props interface with full TSDoc. - Create
src/components/NewComponent/NewComponent.tsxβ implementation. - Create
src/components/NewComponent/index.tsβ barrel. - Create
src/components/NewComponent/__tests__/NewComponent.test.tsxβ or add tosrc/__tests__/. - Add exports to
src/index.ts.
- Create
src/hooks/useNewHook.tswith options, return interface, and implementation. - Add exports to
src/index.ts. - Add tests to
src/__tests__/useNewHook.test.ts.
- Node.js: LTS (>=18)
- React Native: >=0.70.0 (peer dependency)
- React: >=17.0.0 (peer dependency)
- Package manager: npm