Quick Reference React Native Cheatsheet
React Native on one page — views, flex layout, presses, lists, input,
platform code, and the traps around Text and flexDirection.
10 sections 10 tables 14 code snippets Expo npx create-expo-app shelf
npx expo start The root component import { View, Text } from "react-native";
export default function App() {
return (
<View>
<Text>Dune</Text>
</View>
);
} This page is React Native on iOS and Android. A web React component will not render here until you swap the tags. A press import { Pressable, Text } from "react-native";
<Pressable onPress={() => setCount(count + 1)}>
<Text>Add</Text>
</Pressable> A picture <Image
source={{ uri: "https://example.com/cover.jpg" }}
style={{ width: 80, height: 120 }}
/> Fill the screen const styles = StyleSheet.create({
screen: { flex: 1, padding: 16 },
row: { flexDirection: "row", gap: 8 },
}); Use the styles <View style={styles.screen}>
<View style={styles.row}>
<Text>Dune</Text>
<Text>412</Text>
</View>
</View> A counter const [count, setCount] = useState(0);
<Pressable onPress={() => setCount((value) => value + 1)}>
<Text>{count}</Text>
</Pressable> Only the rows on screen <FlatList
data={books}
keyExtractor={(item) => item.id}
renderItem={({ item }) => <Text>{item.title}</Text>}
/> An Expo Router link import { Link } from "expo-router";
<Link href="/book/dune">Dune</Link> A local image <Image source={require("./cover.png")} /> Text must be wrapped <View>
<Text>Dune</Text>
</View> Side by side <View style={{ flexDirection: "row" }}>
<Text>Dune</Text>
<Text>412</Text>
</View> How to use this page: start with npx create-expo-app, put every string in Text, and set flex: 1 on the screen. Then render the books with FlatList and handle taps with Pressable. |