React Native Cursor Rules: Mobile Best Practices Guide

Professional React Native cursor rules guiding component architecture, TypeScript, navigation, testing with Jest and Detox, and performance optimization for cross‑platform iOS and Android apps.

November 14, 2025
react-nativecursor-rulesmobileiosandroid

Overview

Professional cursor rules for React Native that guide component architecture, navigation, typing, and testing. These rules help AI assistants generate context-aware, maintainable code for cross-platform mobile apps.

Note:

Focus on TypeScript, hooks-based components, navigation patterns, native module boundaries, and performance-conscious code generation.

Rules Configuration

.cursor/rules/react-native.mdc

---
description: Enforces best practices for React Native development, focusing on context-aware code generation, modern patterns, and maintainable architecture. Provides comprehensive guidelines for writing clean, efficient, and secure React Native code with proper context.
globs: **/*.{js,jsx,tsx}
---
# React Native Best Practices

You are an expert in React Native programming and related technologies.
You understand modern React Native development practices, architectural patterns, and the importance of providing complete context in code generation.

### Context-Aware Code Generation
- Always provide complete module context including imports, exports, and type definitions
- Include relevant configuration files (e.g., metro.config.js, package.json) when generating projects
- Generate complete function signatures with proper parameter types, return types, and generics
- Include comprehensive comments explaining the purpose, parameters, and return values
- Provide context about the module's role in the larger system architecture

### Code Style and Structure
- Follow clean code principles with meaningful names and proper documentation
- Structure code in logical modules following domain-driven design principles
- Implement proper separation of concerns (components, styles, utils, services)
- Use modern React Native features (hooks, context API, TypeScript) appropriately
- Maintain consistent code formatting using Prettier or similar tools

### Testing and Quality
- Write comprehensive unit tests with proper test context
- Include integration tests for critical paths
- Use proper mocking strategies with Jest
- Implement E2E tests with Detox
- Include performance tests for critical components
- Maintain high test coverage for core business logic

### Security and Performance
- Implement proper input validation and sanitization
- Use secure authentication and token management
- Configure proper CORS and CSRF protection
- Implement rate limiting and request validation
- Use proper caching strategies
- Optimize code execution and memory usage

### Examples

```jsx
/**
 * CustomButton is a reusable button component.
 * Provides consistent styling and behavior for buttons.
 */
import React from 'react';
import { TouchableOpacity, Text, StyleSheet } from 'react-native';

export function CustomButton({ title, onPress }) {
  return (
    <TouchableOpacity style={styles.button} onPress={onPress}>
      <Text style={styles.buttonText}>{title}</Text>
    </TouchableOpacity>
  );
}

const styles = StyleSheet.create({
  button: {
    padding: 12,
    backgroundColor: '#007AFF',
    borderRadius: 8,
  },
  buttonText: {
    color: '#FFFFFF',
    fontSize: 16,
    fontWeight: 'bold',
  },
});

Key Features

📦

Complete Code Context

Imports, types, and module roles are included automatically

🧩

TypeScript & Hooks

Functional components, custom hooks, and strong typing

🧭

Navigation Patterns

Stack, tabs, and deep linking with predictable flows

Testing Built-In

Jest unit tests and Detox end‑to‑end coverage

Performance Focus

Memoization, virtualization, and efficient rendering

🔌

Native Modules

Clear boundaries and secure platform integrations

Installation

1

Choose Your IDE

Select the appropriate file path based on your development environment.

2

Create the Rules File

Create the cursor rules file in your project:

Create file: .cursor/rules/react-native.mdc

3

Add the Rules Configuration

Copy the rules configuration above into your newly created file.

4

Start Building

Your AI assistant will now follow React Native best practices automatically.

Use Cases

Component Library

Reusable UI components with consistent styles and props

Navigation Flows

Stack and tab navigators with deep linking support

API Integration

Type-safe services, caching, and error handling

Native Bridges

Platform modules with clear interfaces and testing

Standards Reference

StandardDescriptionEnforcement
Type SafetyStrict TypeScript types and interfacesRequired for components
TestingJest unit tests; Detox E2EAuto-generated patterns
SecurityInput validation and auth flowsBuilt into patterns
ArchitectureHooks, context, services separationEnforced via modules
PerformanceVirtualized lists and memoizationEncouraged in examples

Best Practices

Code Organization

  • Components handle UI only
  • Hooks encapsulate reusable logic
  • Services manage data access and side effects
  • Context provides app-level state where needed

Testing Strategy

  • Unit tests for components and hooks
  • Integration tests for navigation flows
  • Mock external dependencies appropriately
  • Measure coverage for core features

Note:

These rules work with any React Native project. Adjust platform-specific sections as needed for iOS and Android.