Skip to content

Latest commit

Β 

History

124 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ“¦ React Native TypeScript Library Starter

CI npm version npm downloads License: MIT Platform TypeScript

A modern, production-ready starter for building React Native TypeScript libraries. Ships with dual CJS/ESM output, full test coverage, and AI-ready project conventions out of the box.


πŸ†• What's new in 3.0

  • ⚑ Modern toolchain β€” React Native 0.87 / React 19 dev environment, TypeScript 5.9 with bundler module resolution
  • πŸ¦€ oxlint + oxfmt β€” Rust-based linting and formatting replace ESLint + Prettier (lints the whole repo in milliseconds)
  • πŸ“¦ builder-bob 0.43 β€” ESM-enabled dual CJS/ESM output with per-condition type declarations and a spec-correct exports map
  • πŸ§ͺ RNTL v14 β€” tests migrated to the async render/renderHook API on the universal test renderer
  • πŸ§™ Interactive setup wizard β€” npm run setup configures name, author, repo URLs, license, and keywords in one pass
  • πŸͺ Husky v9 β€” git hooks install automatically on npm install

See the full CHANGELOG for all changes including the 2.0.0 redesign.


🌟 Features

  • πŸ“¦ react-native-builder-bob β€” dual CJS + ESM output + per-condition TypeScript declarations
  • πŸ”’ Strict TypeScript β€” noImplicitAny, strictNullChecks, noUnusedLocals
  • πŸ§ͺ Jest + @testing-library/react-native v14 β€” full async test suite with coverage thresholds
  • πŸ¦€ oxlint + oxfmt β€” Rust-fast lint + format, enforced on commit via lint-staged
  • πŸͺ Husky v9 + commitlint β€” conventional commits, hooks install on npm install
  • βš™οΈ GitHub Actions β€” CI pipeline (typecheck + lint + format-check + test + build)
  • πŸ” Renovate β€” grouped weekly dependency updates
  • πŸ€– AI-ready β€” AGENTS.md conventions file for Claude Code, Cursor, Copilot & friends
  • AI-Ready β€” AGENTS.md, Cursor rules, and full TSDoc on every export
  • Interactive setup wizard β€” npm run setup to configure your library in 60 seconds
  • Example component and hook β€” reference implementations to clone from

πŸš€ Quick Start

1. Clone and install

git clone https://github.com/WrathChaos/react-native-typescript-library-starter.git my-library
cd my-library
npm install

2. Set up git hooks

Git hooks are installed automatically when you run npm install (via the prepare script). No extra step needed.

3. Configure the library

Run the interactive setup wizard. It walks through every field one by one, shows a preview of all planned changes, and asks for confirmation before writing anything:

npm run setup

The wizard will ask for:

  • Package name β€” your npm name (e.g. react-native-my-library)
  • Description β€” one sentence
  • GitHub username / org β€” used to build repo URLs automatically
  • GitHub repository name β€” defaults to your package name
  • Author name & email
  • License β€” MIT, Apache-2.0, ISC, GPL-3.0, or Unlicensed
  • Keywords β€” optional, comma-separated extras

After confirmation it updates package.json, README.md, AGENTS.md, and CONTRIBUTING.md in one go.

4. Replace the example code

The src/ folder contains a fully-typed example component and hook. Use them as reference, then replace with your own:

src/
β”œβ”€β”€ components/MyComponent/   β†’ replace with your component
β”œβ”€β”€ hooks/useMyHook.ts        β†’ replace with your hook
└── index.ts                  β†’ update exports

5. Build and verify

npm run build      # outputs to lib/
npm run typecheck  # type-check without emitting
npm test           # run the test suite

πŸ“ Project Structure

react-native-typescript-library-starter/
β”œβ”€β”€ src/                          # ALL source code
β”‚   β”œβ”€β”€ index.ts                  # Public API entry point
β”‚   β”œβ”€β”€ components/
β”‚   β”‚   └── MyComponent/
β”‚   β”‚       β”œβ”€β”€ MyComponent.tsx
β”‚   β”‚       β”œβ”€β”€ MyComponent.types.ts
β”‚   β”‚       └── index.ts
β”‚   β”œβ”€β”€ hooks/
β”‚   β”‚   └── useMyHook.ts
β”‚   β”œβ”€β”€ types/
β”‚   β”‚   └── index.ts
β”‚   └── __tests__/
β”‚       β”œβ”€β”€ MyComponent.test.tsx
β”‚       └── useMyHook.test.ts
β”œβ”€β”€ lib/                          # Generated by bob (git-ignored)
β”œβ”€β”€ .github/workflows/
β”‚   β”œβ”€β”€ ci.yml                    # PR checks
β”‚   └── release.yml               # Publish pipeline
β”œβ”€β”€ AGENTS.md                     # AI agent instructions
β”œβ”€β”€ CONTRIBUTING.md
β”œβ”€β”€ CHANGELOG.md
β”œβ”€β”€ package.json
β”œβ”€β”€ tsconfig.json
β”œβ”€β”€ tsconfig.build.json
└── babel.config.js

πŸ”§ Scripts

Command Description
npm run build Build library to lib/ via bob
npm run typecheck Type-check without emitting
npm run lint Run oxlint with colored output and auto-fix
npm run lint:ci oxlint without spinner (for CI)
npm run oxfmt Format source files
npm run oxfmt:ci Check formatting (for CI)
npm test Run Jest tests
npm run test:watch Jest in watch mode
npm run test:coverage Jest with coverage report

πŸ“¦ Build Output

react-native-builder-bob produces three output targets inside lib/:

Output Path Used by
CommonJS lib/commonjs/ Node.js, bundlers with require()
ESM lib/module/ Modern bundlers, tree-shaking
TypeScript lib/typescript/ Type declarations for consumers

The package.json exports field routes consumers to the correct output automatically.


🧩 Example Component

import { MyComponent } from "your-library";

export default function App() {
  return (
    <MyComponent
      title="Hello World"
      description="A fully-typed example component."
      enableButton
      buttonText="Tap me"
      onPress={() => console.log("pressed")}
    />
  );
}

MyComponent Props

Prop Type Default Description
title string β€” Primary title text (required)
description string β€” Optional description below title
enableButton boolean false Renders an action button
buttonText string "Press me" Button label
onPress () => void β€” Button press callback
style StyleProp<ViewStyle> β€” Root container style override
titleStyle StyleProp<TextStyle> β€” Title text style override
descriptionStyle StyleProp<TextStyle> β€” Description text style override
buttonStyle StyleProp<ViewStyle> β€” Button container style override
buttonTextStyle StyleProp<TextStyle> β€” Button label style override
accessibilityLabel string title Accessibility label for the container
testID string "my-component" Test ID for querying in tests

πŸͺ Example Hook

import { useMyHook } from "your-library";

function Counter() {
  const { count, increment, decrement, reset, isAtMax, isAtMin } = useMyHook({
    initialValue: 0,
    max: 10,
    min: 0,
    step: 1,
  });

  return (
    <View>
      <Text>{count}</Text>
      <Button title="+" onPress={increment} disabled={isAtMax} />
      <Button title="-" onPress={decrement} disabled={isAtMin} />
      <Button title="Reset" onPress={reset} />
    </View>
  );
}

useMyHook Options

Option Type Default Description
initialValue number 0 Starting counter value
max number β€” Upper bound (no limit if omitted)
min number 0 Lower bound
step number 1 Increment/decrement amount

useMyHook Return

Key Type Description
count number Current counter value
increment () => void Increment by step
decrement () => void Decrement by step
reset () => void Reset to initialValue
isAtMax boolean true when count >= max
isAtMin boolean true when count <= min

πŸ§ͺ Testing

Tests use Jest and @testing-library/react-native.

npm test                 # run all tests
npm run test:coverage    # with coverage report

Coverage thresholds are enforced in package.json:

  • Branches: 70%
  • Functions / Lines / Statements: 80%

πŸ“ Commit Conventions

This project enforces Conventional Commits via commitlint:

feat: add MyButton component
fix: correct accessibility role
test: add boundary cases for useMyHook
docs: update README with new props
chore: upgrade dependencies

βš™οΈ CI

CI Pipeline (.github/workflows/ci.yml)

Runs on every push and pull request to main:

  1. Typecheck β€” tsc --noEmit
  2. Lint β€” oxlint + oxfmt check
  3. Test β€” Jest with coverage
  4. Build β€” bob build (only runs after all checks pass)

πŸ€– AI / LLM Usage

This starter is designed to be AI-friendly:

  • AGENTS.md β€” read this file first when working with an AI agent. It contains the full directory map, all runnable commands, conventions, naming rules, and do/don'ts.
  • .cursor/rules/library-conventions.mdc β€” Cursor AI rules that automatically enforce component/hook patterns.
  • TSDoc everywhere β€” every exported function, component, prop, and type has @param, @returns, and @example documentation. This maximises AI autocomplete quality.
  • Strict TypeScript β€” strict mode produces accurate types that AI tools can reason about reliably.
  • Conventional Commits β€” predictable commit history helps AI tools summarize changes and generate release notes.

Using with Cursor

The .cursor/rules/library-conventions.mdc rule is auto-applied to all src/**/*.ts and src/**/*.tsx files. It enforces component structure, hook patterns, and TSDoc requirements.

Using with Claude / ChatGPT

Paste the contents of AGENTS.md into the system prompt or the start of a conversation for best results.


πŸ”— Peer Dependencies

"peerDependencies": {
  "react": ">=17.0.0",
  "react-native": ">=0.70.0"
}

🀝 Contributing

See CONTRIBUTING.md for the full guide.


πŸ“œ Changelog

See CHANGELOG.md.


πŸ“„ License

MIT β€” see LICENSE.


πŸ‘€ Author

kuraydev β€” kurayogun@gmail.com
freakycoder.com

About

πŸš€ Production-ready starter for React Native TypeScript libraries β€” dual CJS/ESM output, strict types, full tests, automated releases, and AI-ready tooling out of the box.

Topics

Resources

Contributing

Stars

65 stars

Watchers

2 watching

Forks

Releases

Packages

Used by

Contributors

Languages