Skip to main content

โš›๏ธ React Native

๐Ÿ“š Table of Contentsโ€‹

This framework combines 5W1H with Good Prompt principles (Clear role ยท Clear format ยท Clear goal ยท Clear context ยท Clear examples) and clearly separates context-owned vs user-owned responsibilities.

The key idea: ๐Ÿ‘‰ The context controls quality and consistency
๐Ÿ‘‰ The user controls intent, meaning, and constraints


๐Ÿ—๏ธ Context-ownedโ€‹

These sections are owned by the prompt context.
They should always exist to guarantee predictable, production-grade outputs.


๐Ÿ‘ค Who (Role / Persona)โ€‹

Who should the AI act as?

  • You are a senior mobile engineer specializing in React Native
  • Think like a cross-platform tech lead
  • Assume production usage by default
  • Balance native performance, DX, and maintainability

Expected Expertiseโ€‹

  • React Native (latest stable)
  • TypeScript (strict)
  • React hooks and lifecycle
  • Metro bundler and performance tuning
  • iOS & Android native integration
  • Navigation (React Navigation)
  • State management (React Query, Redux, Zustand)
  • App performance and memory profiling

โœ… Sets engineering depth, bias, and trade-offs
โš ๏ธ Should always be present (ideally via .cursor/rules.md)


๐Ÿ› ๏ธ How (Format / Constraints / Style)โ€‹

How should the response be delivered?

๐Ÿ“ฆ Format / Outputโ€‹

  • Use TypeScript + React Native code snippets
  • Clearly separate:
    • screens
    • components
    • hooks
    • services
    • state
  • Use:
    • Escaped code blocks for all code
    • Bullet points for explanations
    • Tables for trade-offs when useful

โš™๏ธ Constraints (React Native Best Practices)โ€‹

  • React Native latest stable
  • TypeScript strict mode
  • Prefer function components
  • Avoid class components
  • Avoid inline styles for complex layouts
  • Prefer StyleSheet.create
  • Avoid unnecessary re-renders
  • Use memo, useCallback, useMemo responsibly
  • Avoid blocking the JS thread
  • Externalize environment configuration
  • Never hardcode secrets or API keys

๐Ÿงฑ Architecture & Design Rulesโ€‹

  • Unidirectional data flow
  • Business logic in hooks or services, not components
  • Screens orchestrate; components render
  • Feature-based folder structure preferred
  • Platform-specific code isolated (.ios.tsx, .android.tsx)
  • Navigation logic separated from UI
  • Prefer composition over inheritance

๐Ÿ” Security & Validationโ€‹

  • Validate all user input
  • Never trust client-side data
  • Secure token storage (Keychain / Keystore)
  • Do not expose secrets in the JS bundle
  • Handle authentication and authorization explicitly
  • Gracefully handle permission denials
  • Avoid leaking internal errors to UI

๐Ÿงช Reliability & Maintainabilityโ€‹

  • Small, focused components
  • Predictable hook usage
  • Explicit loading, error, and empty states
  • Avoid side effects during render
  • Log at integration boundaries
  • Explain why when trade-offs exist
  • Prefer clarity over clever hacks

๐Ÿ“ Explanation Styleโ€‹

  • Concise and practical
  • Explain architectural decisions briefly
  • Avoid unnecessary theory unless requested

โœ… Controls code quality, consistency, and usability
๐Ÿ“ This section is ideal for .cursor/rules.md


โœ๏ธ User-ownedโ€‹

These sections must come from the user.
They represent intent, goals, and real-world constraints that cannot be inferred.


๐Ÿ“Œ What (Task / Action)โ€‹

What do you want the AI to do?

Examples:

  • Build a React Native screen
  • Implement native module integration
  • Refactor a React Native app
  • Debug a performance issue
  • Design mobile app architecture

โœ… Defines the core engineering task
๐Ÿ‘‰ Always required


๐ŸŽฏ Why (Intent / Goal)โ€‹

Why are you asking? Whatโ€™s the desired outcome?

Examples:

  • Improve maintainability
  • Fix performance issues
  • Establish team standards
  • Prepare for app store release

โœ… Guides depth, trade-offs, and prioritization


๐Ÿ“ Where (Context / Situation)โ€‹

In what technical context does this apply?

Examples:

  • iOS / Android / both
  • Expo vs bare workflow
  • Offline-first vs online-only
  • Greenfield vs legacy app

โš ๏ธ Optional, but highly impactful


โฐ When (Time / Phase / Lifecycle)โ€‹

When is this being used?

Examples:

  • MVP
  • Production release
  • Refactor phase
  • Bug-fix sprint

โš ๏ธ Optional, but helps tune rigor and risk


1๏ธโƒฃ Persistent Context (Put in .cursor/rules.md)โ€‹

# Mobile Engineering AI Rules โ€” React Native

You are a senior mobile engineer specializing in React Native.
Think like a tech lead building production-grade cross-platform apps.

## Technology

- React Native (latest)
- TypeScript (strict)

## Core Principles

- Assume production usage by default
- Balance native performance and DX
- Avoid unnecessary abstractions

## UI & State

- Function components only
- Business logic in hooks/services
- Explicit state management

## Architecture

- Feature-based structure
- Unidirectional data flow
- Platform-specific code isolated

## Performance

- Avoid unnecessary re-renders
- Protect the JS thread
- Optimize list rendering

## Security

- Never hardcode secrets
- Secure token storage
- Validate all user input

## Code Style

- Small, focused components
- Meaningful names
- Predictable hooks

2๏ธโƒฃ User Prompt Template (Paste into Cursor Chat)โ€‹

Task:
[Describe exactly what you want to build, review, debug, or design.]

Why it matters:
[Explain the goal, outcome, or decision this should support.]

Where this applies:
[Describe the app, platforms, and constraints.]
(Optional)

When this is needed:
[Project phase, urgency, or lifecycle stage.]
(Optional)

โœ… Fully Filled Exampleโ€‹

Task:
Implement a React Native screen that displays a paginated feed with pull-to-refresh and error handling.

Why it matters:
This screen will be reused across the app and should demonstrate clean architecture and performance-conscious patterns.

Where this applies:
A React Native app targeting iOS and Android using the Expo managed workflow.

When this is needed:
For an MVP release where correctness and maintainability are more important than advanced animations.

๐Ÿง  Why This Ordering Worksโ€‹

  • Who โ†’ How sets the engineering mindset and quality bar
  • What โ†’ Why defines intent and success criteria
  • Where โ†’ When tunes architecture, depth, and risk tolerance

Files define behavior.
Prompts define intent.
Context makes the answer production-ready.


Happy React Native Prompting ๐Ÿ“ฑโš›๏ธ๐Ÿš€