Enforces React Native coding standards including functional components, naming conventions, TypeScript interfaces, StyleSheet usage, hooks optimization, and folder structure. Use when writing React Native code, creating components, or structuring React Native projects.
const or let to declare variables. Use const by default, unless a variable needs to be reassigned.getComponent inside render method. Always separate components into their own files when possible.// CONSTANT_CASE
const PRIMARY_COLOR = '#FF0000';
const FONT_SIZE_LARGE = 18;
const API_ENDPOINT = 'https://api.example.com';
// PascalCase for components and interfaces
interface UserProfile {
firstName: string; // camelCase
lastName: string; // camelCase
}
const UserCard = () => { // PascalCase component
// ...
};
any type is restricted - avoid using any unless absolutely necessaryAlways use interfaces to define object shapes:
interface Person {
name: string;
age: number;
}
interface ButtonProps {
title: string;
onPress: () => void;
disabled?: boolean;
}
// Absolute path (preferred)
import { Button } from '@/components/Button';
import { UserService } from '@/services/UserService';
// Relative path (same directory only)
import { helper } from './helper';
StyleSheet.create()// styles.ts (separate file)
const styles = StyleSheet.create({
container: { flex: 1 },
title: { fontFamily: 'Inter-Medium', fontSize: 18, color: '#000' },
});
export default styles;
// Component usage
import styles from './styles';
const MyComponent = () => (
<View style={styles.container}>
<Text style={styles.title}>Hello</Text>
</View>
);
Never use inline styles:
// ❌ Bad
<Text style={{ fontSize: 16, color: 'red' }}>Hello</Text>
// ✅ Good
<Text style={styles.title}>Hello</Text>
// ✅ Good - Arrow function component
const MyComponent = () => {
return <Text>Hello, React Native!</Text>;
};
// ❌ Avoid - Traditional function
function MyComponent() {
return <Text>Hello</Text>;
}
useCallback when memoizing functionsuseMemo when memoizing computed values// ❌ Bad - Function recreated on every render
const FooComponent = () => {
const onPress = () => { /* ... */ };
return <Bar onPress={onPress} />;
};
// ✅ Good - Function memoized with dependencies
const FooComponent = ({ a, b }) => {
const onPress = useCallback(() => { /* ... */ }, [a, b]);
return <Bar onPress={onPress} />;
};
// ✅ Good - Memoized computed value
const ExpensiveComponent = ({ items }) => {
const sortedItems = useMemo(() => items.sort((a, b) => a.value - b.value), [items]);
return <List items={sortedItems} />;
};
Follow this standard folder structure:
src/
├── components/ # Common reusable components (Button, Input, etc.)
├── screens/ # Application screens/features
├── navigations/ # Navigation configs and navigators
├── services/ # Common services (API calls, etc.)
├── utils/ # Utility functions (calculations, formatters, constants)
├── types/ # TypeScript interfaces and enums
├── redux/ # Redux actions, reducers, and store
└── assets/ # Images, vectors, fonts, etc.
App.tsx # Main component that starts the app
index.ts # Entry point of the application
components/: Generic, reusable components used across the appscreens/: Feature-specific screens/pagesservices/: API calls, external service integrationsutils/: Pure utility functions, helpers, constantstypes/: Shared TypeScript types, interfaces, enumsredux/: State management (actions, reducers, store)assets/: Static assets (images, fonts, icons)When creating a new component:
const for variable declarationsstyles.ts file using StyleSheet.create()useCallback/useMemo used appropriately for optimizationcomponents/ vs screens/)