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 {
// PascalCase
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;
}
Benefits:
// Absolute path (preferred)
import { Button } from '@/components/Button';
import { UserService } from '@/services/UserService';
// Relative path (same directory only)
import { helper } from './helper';
// Named exports (preferred)
export const calculateTotal = () => { /* ... */ };
export const formatDate = () => { /* ... */ };
// Default export (when needed)
const UserCard = () => { /* ... */ };
export default UserCard;
Create reusable base styles:
const baseStyle = StyleSheet.create({
flex: {
flex: 1,
},
justifyContentCenter: {
justifyContent: 'center',
},
centralize: {
justifyContent: 'center',
alignItems: 'center',
},
p4: {
padding: 4,
},
m8: {
margin: 8,
},
});
StyleSheet.create()// styles.ts (separate file)
const styles = StyleSheet.create({
container: {
flex: 1,
},
title: {
fontFamily: 'Inter-Medium',
fontSize: 18,
color: '#000',
},
errorMessage: {
fontFamily: 'Inter-Regular',
color: 'red',
},
textAlignCenter: {
textAlign: 'center',
},
});
export default styles;
// Component usage
import styles from './styles';
const MyComponent = () => {
return (
<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>;
};
// ✅ Good - Arrow function event handler
<Button onPress={() => console.log('Button clicked!')} title="Click me" />
// ❌ 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 = () => {
// onPress is newly created in every render
};
return <Bar onPress={onPress} />;
};
// ✅ Good - Function memoized with dependencies
const FooComponent = ({ a, b }) => {
const onPress = useCallback(() => {
// onPress is reused if a & b don't change
}, [a, b]);
return <Bar onPress={onPress} />;
};
// ✅ Good - Memoized computed value
const ExpensiveComponent = ({ items }) => {
const sortedItems = useMemo(() => {
return items.sort((a, b) => a.value - b.value);
}, [items]);
return <List items={sortedItems} />;
};
// ✅ Good - Using selector
function TodoList() {
const todos = useSelector(state => state.todos);
const completedTodos = useSelector(state =>
state.todos.filter(todo => todo.completed)
);
return <View>{/* ... */}</View>;
}
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/)