rules/react-native/coding-style.md
This file extends common/coding-style.md with React Native / Expo specific content.
interface or type; do not use React.FC.interface AvatarProps {
uri: string
size?: number
onPress?: () => void
}
export function Avatar({ uri, size = 40, onPress }: AvatarProps) {
return (
<Pressable onPress={onPress}>
<Image source={{ uri }} style={{ width: size, height: size, borderRadius: size / 2 }} />
</Pressable>
)
}
Pick ONE styling system per project and stay consistent. StyleSheet.create() is the framework-native option; utility-class libraries (e.g. NativeWind) are a common alternative. This rule is library-agnostic — what matters is consistency and avoiding inline allocations.
StyleSheet.create() at module scope — never build style objects inline inside render/JSX on hot paths (it allocates on every render).// WRONG: inline style object recreated every render
<View style={{ padding: 16, backgroundColor: '#fff' }} />
// CORRECT (StyleSheet)
const styles = StyleSheet.create({ card: { padding: 16, backgroundColor: '#fff' } })
<View style={styles.card} />
// CORRECT (NativeWind)
<View className="p-4 bg-white" />
Component.ios.tsx, Component.android.tsx) for substantial divergence.Platform.select() / Platform.OS for small differences only.react-native-safe-area-context; do not hardcode status bar / notch offsets.@/components/...) instead of long relative chains.console.log in shipped code. Use a logger and strip logs in production builds.All TypeScript rules from rules/typescript/ apply (explicit types on public APIs, avoid any, Zod for validation, immutable updates). This file only adds RN-specific guidance on top.