liminfo

React Native Reference

Free reference guide: React Native Reference

25 results

About React Native Reference

The React Native Reference is a comprehensive, searchable cheat sheet for cross-platform mobile development with React Native. It covers 27 entries across six categories: Components, Navigation, Styling, Native Modules, State Management, and Animation. Each entry shows the exact JSX or JavaScript syntax, explains what it does, and provides a complete runnable code example — so you can quickly copy and adapt patterns whether you are building a new screen, integrating device hardware, or optimizing performance.

This reference is designed for React Native developers at all experience levels. The Components section covers the core building blocks: View (container), Text (display text), Image (with resizeMode), TextInput (controlled input), FlatList (virtualized scrollable list), and TouchableOpacity (tap feedback). The Navigation section covers React Navigation's createStackNavigator and createBottomTabNavigator, along with navigation.navigate() for screen transitions and passing route params, and navigation.goBack() for back navigation.

The Styling section explains StyleSheet.create(), Flexbox layout with flexDirection and justifyContent, Dimensions.get("window") for responsive sizing, and Platform.select() for iOS/Android-specific styles. Native Modules covers NativeModules for bridging, Linking.openURL() for external URLs and tel: links, PermissionsAndroid.request() for runtime Android permissions, and AsyncStorage for persistent local key-value storage. State Management covers useState, useEffect with cleanup, useContext for global state, and Redux Toolkit with createSlice and configureStore.

Key Features

  • Core React Native components: View, Text, Image (resizeMode), TextInput, FlatList (keyExtractor/renderItem), TouchableOpacity
  • React Navigation: createStackNavigator, createBottomTabNavigator, navigate() with params, goBack()
  • Styling system: StyleSheet.create(), Flexbox (flexDirection, justifyContent, alignItems), responsive Dimensions, Platform.select()
  • Native Modules: NativeModules bridge, Linking.openURL(), PermissionsAndroid.request(), AsyncStorage get/set
  • React Hooks for state: useState, useEffect with dependency array and cleanup, useContext with Provider pattern
  • Redux Toolkit: createSlice with reducers, configureStore, useSelector and useDispatch integration patterns
  • Animation API: Animated.Value with timing(), spring() with friction/tension, LayoutAnimation for layout transitions
  • Category-based navigation to jump directly to Components, Navigation, Styling, Native Modules, State Management, or Animation

Frequently Asked Questions

What is the difference between View and Text in React Native?

View is the fundamental container component in React Native, equivalent to a div in HTML. It is used to group and layout other components using Flexbox. Text is the only component that can display string content — unlike the web, in React Native you cannot render raw text outside a Text component. Every piece of visible text must be wrapped in a Text (or a component that renders Text internally).

How do I create a scrollable list efficiently in React Native?

Use FlatList instead of ScrollView for long or dynamic lists. FlatList uses virtualization — it only renders the items currently visible on screen plus a small buffer, keeping memory usage low even with thousands of items. You must provide a data array, a keyExtractor function returning a unique string per item, and a renderItem function that returns the JSX for each row.

How does navigation work with React Navigation?

React Navigation provides navigator components like createStackNavigator() for push/pop screen transitions and createBottomTabNavigator() for tab-bar navigation. Wrap your screens inside a navigator, then use the navigation prop that React Navigation injects into every screen component. Call navigation.navigate("ScreenName", { param: value }) to move to another screen and pass data, and read params with route.params.

What is the difference between StyleSheet.create() and inline styles?

StyleSheet.create() validates style properties at development time and can apply performance optimizations on some React Native bridges by sending style IDs instead of full objects over the bridge. Inline styles create a new object on every render, which can slow down components that re-render frequently. For static or rarely-changing styles, always prefer StyleSheet.create(). Dynamic styles (computed at runtime) can be inline or merged with StyleSheet styles using an array syntax.

How do I handle Android and iOS style differences in React Native?

Use Platform.select({ ios: value, android: value }) inside a StyleSheet to apply platform-specific values. For example, set paddingTop to 44 on iOS (to account for the notch) and 0 on Android. You can also use Platform.OS === "ios" in conditional logic, or create separate files with .ios.js and .android.js extensions that React Native will automatically pick up for the correct platform.

How does AsyncStorage work and when should I use it?

AsyncStorage (from @react-native-async-storage/async-storage) is a simple, persistent, unencrypted key-value store for React Native. Use it to save user preferences, auth tokens, or app state that should survive app restarts. All operations are asynchronous and return Promises, so use await AsyncStorage.setItem("key", "value") and await AsyncStorage.getItem("key"). For sensitive data like passwords, use a secure storage library instead.

When should I use Redux Toolkit instead of useState or useContext?

Use useState for local component state (form inputs, toggle visibility). Use useContext for medium-complexity shared state like theme or locale that a subtree of components needs. Use Redux Toolkit when your app has complex state logic that many disconnected components need to read and update, when you need time-travel debugging with Redux DevTools, or when state updates depend on the previous state in non-trivial ways. Redux Toolkit's createSlice simplifies boilerplate significantly compared to plain Redux.

What is useNativeDriver in the Animated API and why does it matter?

Setting useNativeDriver: true in Animated.timing() or Animated.spring() moves the animation to the native thread, bypassing the JavaScript bridge entirely. This gives you smooth 60fps animations even when the JS thread is busy. The trade-off is that only a subset of style properties (transform, opacity) support the native driver. Layout-affecting properties like width, height, and top/left cannot use useNativeDriver and must run on the JS thread.