In React Native, components are the building blocks of any mobile application. These React Native components let you create a structured user interface (UI) that works seamlessly across iOS and Android. Whether it’s text, images, buttons, or containers, React Native provides a wide range of components that can be used to build cross-platform mobile apps.
Page Contents
This guide will take you through the essential React Native components like View, Text, Image, and Button, and how to use them effectively in your projects. By the end of this article, you will have a solid understanding of React Native components and how to build UIs with them.
What are React Native Components?
React Native components are like building blocks for mobile applications. They help you define your app’s structure, layout, and design. There are two types of components in React Native:
- Core Components: These are provided by React Native itself and include components like
View,Text,Image, andButton. - Custom Components: You can create your components by combining core components.
This article will focus on the most common core components and how to use them in your React Native projects.
View Component
The View component is one of the most fundamental building blocks in React Native. It acts as a container for other components and can be used to style and position elements in your app.
Here’s a simple example of the View component:
import React from 'react';
import { View, Text } from 'react-native';
const App = () => {
return (
<View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
<Text>Welcome to React Native!</Text>
</View>
);
};
export default App;
In this example:
- The
Viewcomponent acts like adivin web development and is used as a container. - The
styleprop defines the layout of theView, using Flexbox properties likejustifyContentandalignItemsto centre theTextcomponent.
Text Component
The Text component is used to display textual content in your app. It can be styled, nested, and even include clickable links.
Here’s how to use the Text component:
import React from 'react';
import { Text, View } from 'react-native';
const App = () => {
return (
<View style={{ padding: 20 }}>
<Text style={{ fontSize: 24, fontWeight: 'bold' }}>Hello, World!</Text>
<Text>This is a simple text component in React Native.</Text>
</View>
);
};
export default App;
In this example:
- The
Textcomponent is styled with a larger font size and bold weight. - Multiple
Textcomponents can be used inside aViewto display different lines of text.
Image Component
The Image component is used to display images in your React Native app. It supports both local and remote images.
Here’s an example of the Image component:
import React from 'react';
import { View, Image } from 'react-native';
const App = () => {
return (
<View style={{ alignItems: 'center', marginTop: 50 }}>
<Image
source={{ uri: 'https://reactnative.dev/img/tiny_logo.png' }}
style={{ width: 100, height: 100 }}
/>
</View>
);
};
export default App;
In this example:
- The
Imagecomponent loads a remote image using a URL. - The
styleprop defines the width and height of the image.
Button Component
The Button component provides a simple way to add clickable buttons to your app. It supports text labels and onPress events.
Here’s how to use the Button component:
import React from 'react';
import { View, Button, Alert } from 'react-native';
const App = () => {
return (
<View style={{ marginTop: 50 }}>
<Button
title="Press Me"
onPress={() => Alert.alert('Button Pressed')}
/>
</View>
);
};
export default App;
In this example:
- The
Buttoncomponent displays a simple button with the label “Press Me.” - The
onPressevent triggers an alert when the button is clicked.
Custom Components
React Native allows you to create custom components by combining core components. This helps in making your code more reusable and organized.
Here’s an example of a custom Card component:
import React from 'react';
import { View, Text, StyleSheet } from 'react-native';
const Card = ({ title, content }) => {
return (
<View style={styles.card}>
<Text style={styles.title}>{title}</Text>
<Text>{content}</Text>
</View>
);
};
const styles = StyleSheet.create({
card: {
backgroundColor: '#f9f9f9',
padding: 20,
borderRadius: 10,
marginBottom: 10,
shadowColor: '#000',
shadowOpacity: 0.2,
shadowOffset: { width: 0, height: 1 },
},
title: {
fontSize: 18,
fontWeight: 'bold',
},
});
export default Card;
In this example:
- The
Cardcomponent is a custom component that combines aViewandTextcomponents. - It uses
StyleSheetfor consistent styling and can be reused with different props.
Conclusion
In this React Native Components guide, we covered the essential components that you’ll use to build your mobile apps. From basic layout using View to displaying text and images, React Native provides a robust set of components to create cross-platform applications. By understanding how to use these components, you’ll be well-equipped to start building more complex UIs and features in your mobile apps.
Parvesh Sandila is a results-driven tech professional with 8+ years of experience in web and mobile development, leadership, and emerging technologies.
After completing his Master’s in Computer Applications (MCA), he began his journey as a programming mentor, guiding 100+ students and helping them build strong foundations in coding. In 2019, he founded Owlbuddy.com, a platform dedicated to providing free, high-quality programming tutorials for aspiring developers.
He then transitioned into a full-time programmer, where his hands-on expertise and problem-solving skills led him to grow into a Team Lead and Technical Project Manager, successfully delivering scalable web and mobile solutions. Today, he works with advanced technologies such as AI systems, RAG architectures, and modern digital solutions, while also collaborating through a strategic partnership with Technobae (UK) to build next-generation products.
