Catalog / React Native Cheatsheet
React Native Cheatsheet
A quick reference guide for React Native development, covering core components, APIs, styling, navigation, and state management.
Core Components & APIs
Basic Components
|
The most fundamental component for building UI. Equivalent to a |
|
Used to display text. Must be used for any text content. |
|
Displays images. Supports local and remote images. |
|
Allows users to input text. Used for forms and user input. |
|
A scrollable container. Used for content that exceeds the screen size. |
|
Efficiently renders large lists of data. Optimized for performance. |
Core APIs
|
Displays an alert dialog with an optional title, message, and buttons. |
|
Provides access to the screen dimensions (width and height). |
|
Detects the platform the app is running on (e.g., ‘ios’, ‘android’). |
|
A simple, unencrypted, persistent, key-value storage system. |
|
Provides an interface to interact with incoming and outgoing app links. |
|
Provides events and methods for handling the virtual keyboard. |
Platform Specific Code
Use Example:
|
Styling & Layout
Styling with StyleSheet
Use Example:
|
Common Styles
|
Makes a component take up all available space. |
|
Controls the direction of items in a flex container ( |
|
Defines how flex items are aligned along the cross axis ( |
|
Defines how flex items are aligned along the main axis ( |
|
Defines spacing around elements. Can specify |
|
Sets the background color of a component. |
Flexbox Layout
React Native uses Flexbox for layout. Understand the concepts of main axis and cross axis for effective UI design.
|
Navigation
React Navigation
React Navigation is a popular library for handling navigation in React Native apps. Install it using:
For Expo managed projects:
|
Stack Navigator
Creating a Stack Navigator |
|
Navigating between screens |
|
Passing parameters |
|
Tab Navigator
Creating a Tab Navigator |
|
State Management
useState Hook
The Example:
|
useReducer Hook
The Example:
|
Context API
The Context API allows you to share state between components without having to pass props manually at every level. Example:
|