React Native
React Native is an open-source UI software framework for developing cross-platform native mobile applications for iOS and Android using JavaScript and React. It enables developers to write code once and deploy it to multiple platforms, leveraging native UI components for optimal performance and user experience. The current stable version is 0.85.1, with new minor versions typically released every two months and frequent patch releases, indicating an active and rapidly evolving development cycle. Key differentiators include its declarative component-based UI paradigm inherited from React, direct access to native device features through JavaScript Interface (JSI), and a vast ecosystem of third-party libraries. Unlike hybrid webview solutions, React Native renders actual native UI elements, which contributes to a more authentic native look and feel, and starting from 0.82, it exclusively uses the New Architecture, removing the legacy bridge for improved performance and concurrency.
Common errors
-
Invariant Violation: "main" has not been registered. This can happen if: * Your app's main component is not defined in AppRegistry.registerComponent. * Your app is not running in a development environment.
cause The entry point component of your React Native application was not correctly registered with `AppRegistry`.fixEnsure that your main `App` component is exported as default and registered in your `index.js` (or similar entry file) using `AppRegistry.registerComponent('AppName', () => App);` where 'AppName' matches the name specified in your `app.json`. -
Error: Unable to resolve module react-native from '...' - Ensure that the module exists in the module map or within any of the configured `node_modules` directories.
cause Metro bundler cannot find the `react-native` package, usually due to incorrect `node_modules`, cache issues, or symlink problems.fixTry deleting `node_modules`, `yarn.lock`/`package-lock.json`, and Metro cache (`npm start --reset-cache` or `yarn start --reset-cache`). Then reinstall dependencies (`npm install` or `yarn install`) and run `cd ios && pod install && cd ..` for iOS projects. -
Command failed with exit code 65: xcodebuild ...
cause A general Xcode build failure on iOS, often related to CocoaPods, outdated dependencies, or project configuration.fixClean the build folder in Xcode (`Product > Clean Build Folder`), then `cd ios && rm -rf build && pod install && cd ..`. Check Xcode logs for specific error messages (e.g., missing headers, linker errors). Update CocoaPods and native dependencies. -
A problem occurred configuring project ':app'. > Failed to install the following Android SDK packages as some licences have not been accepted.
cause Android SDK licenses have not been accepted, preventing Gradle from installing necessary components.fixRun `sdkmanager --licenses` in your Android SDK tools directory (or equivalent for your OS) and accept all licenses. Ensure your `ANDROID_HOME` environment variable is correctly set. -
Error: EMFILE: too many open files, watch '/path/to/project/node_modules/...' - [Full watchman error message]
cause Your system's Watchman process is trying to watch too many files, exceeding the OS limit, common in large projects on macOS.fixRun `watchman watch-del-all` and then `watchman shutdown-server` in your terminal. For persistent issues, consider increasing your system's file watch limits or optimizing your project structure to reduce the number of watched files.
Warnings
- breaking React Native 0.85.x fully removes the legacy bridge and enforces the New Architecture (Fabric, TurboModules, JSI). Projects not yet migrated will face significant breaking changes, especially for custom native modules or older third-party libraries that rely on the old architecture.
- breaking The Jest testing preset has been moved from `react-native` to a separate package, `@react-native/jest-preset`. Tests will fail if the configuration is not updated.
- breaking Support for older Node.js versions has been dropped. React Native 0.85 requires Node.js 20.19.4 or higher.
- breaking The `Animated` module has undergone significant changes in 0.85, including a new C++ animation backend, which allows animating layout properties with the native driver. While generally an improvement, some existing `Animated` code, especially that relying on previous limitations or workarounds, might require adjustments.
- deprecated Deprecated APIs, such as `StyleSheet.absoluteFillObject`, have been entirely removed in 0.85. Using these will result in runtime errors.
- gotcha Upgrading React Native versions, particularly minor versions (e.g., 0.84 to 0.85), often involves manual reconciliation of native project files (Xcode `.xcodeproj`, `.xcworkspace`, `Podfile`, `build.gradle`, `AndroidManifest.xml`). Simply updating `package.json` is insufficient.
Install
-
npm install react-native -
yarn add react-native -
pnpm add react-native
Imports
- { View, Text, StyleSheet }
const { View, Text, StyleSheet } = require('react-native');import { View, Text, StyleSheet } from 'react-native'; - { Platform, Dimensions }
import Platform from 'react-native/Libraries/Utilities/Platform';
import { Platform, Dimensions } from 'react-native'; - SafeAreaView
import SafeAreaView from 'react-native/SafeAreaView';
import { SafeAreaView } from 'react-native';
Quickstart
import React from 'react';
import { SafeAreaView, StyleSheet, Text, View, Platform, StatusBar } from 'react-native';
const App = () => {
const os = Platform.OS === 'ios' ? 'iOS' : 'Android';
return (
<SafeAreaView style={styles.container}>
<StatusBar barStyle="dark-content" />
<View style={styles.content}>
<Text style={styles.title}>Welcome to React Native!</Text>
<Text style={styles.subtitle}>Running on {os} with v0.85.1</Text>
<Text style={styles.description}>
This is a basic React Native application. It demonstrates using core components
like View, Text, and StyleSheet for UI layout and styling.
The SafeAreaView ensures content is not obscured by device notches or status bars.
</Text>
</View>
</SafeAreaView>
);
};
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#F8F8F8',
paddingTop: Platform.OS === 'android' ? StatusBar.currentHeight : 0,
},
content: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
padding: 20,
},
title: {
fontSize: 28,
fontWeight: 'bold',
marginBottom: 10,
color: '#333',
textAlign: 'center',
},
subtitle: {
fontSize: 18,
color: '#666',
marginBottom: 20,
textAlign: 'center',
},
description: {
fontSize: 16,
color: '#555',
lineHeight: 24,
textAlign: 'center',
},
});
export default App;