Core components in React Native create real native user interfaces on your phone. This means your app looks and feels like a normal app made just for that device.
Why core components build native UIs in React Native
Introduction
Syntax
React Native
import { View, Text, Button, Image } from 'react-native'; function MyComponent() { return ( <View> <Text>Hello!</Text> <Button title="Click me" onPress={() => {}} /> <Image source={{uri: 'https://example.com/pic.png'}} /> </View> ); }
Core components like , , and
You write JSX code, but React Native turns it into native widgets behind the scenes.
Examples
React Native
import { Text } from 'react-native'; <Text>Simple native text</Text>
React Native
import { Button, Alert } from 'react-native'; <Button title="Press me" onPress={() => Alert.alert('Pressed!')} />
React Native
import { View, Text } from 'react-native'; <View> <Text>Inside a native container</Text> </View>
Sample App
This app shows a centered text and a native button. When you tap the button, a native alert pops up. The UI uses native components so it feels smooth and natural on your device.
React Native
import React from 'react'; import { View, Text, Button, Alert, StyleSheet } from 'react-native'; export default function App() { return ( <View style={styles.container}> <Text style={styles.title}>Welcome to Native UI!</Text> <Button title="Say Hello" onPress={() => Alert.alert('Hello from native button!')} /> </View> ); } const styles = StyleSheet.create({ container: { flex: 1, justifyContent: 'center', alignItems: 'center', backgroundColor: '#f0f0f0' }, title: { fontSize: 24, marginBottom: 20 } });
Important Notes
Core components are the building blocks that React Native uses to create native apps.
They help your app look and behave like apps made with platform-specific tools.
Using core components means less work to make your app run well on different devices.
Summary
Core components create real native UI elements on iOS and Android.
This makes your app feel fast, smooth, and familiar to users.
You write simple JSX code, and React Native handles the native rendering.
Practice
1. Why do React Native core components create a better user experience on mobile devices?
easy
Solution
Step 1: Understand core components role
Core components likeViewandTextmap directly to native UI elements on each platform.Step 2: Compare with other methods
Unlike web views, core components use native widgets, making apps faster and smoother.Final Answer:
Because they render real native UI elements on iOS and Android -> Option CQuick Check:
Native UI = Better user experience [OK]
Hint: Core components map to native widgets, not web views [OK]
Common Mistakes:
- Thinking React Native uses web views for UI
- Believing core components only work on Android
- Assuming manual native code is always needed
2. Which of the following is the correct way to create a text element using React Native core components?
easy
Solution
Step 1: Identify React Native core text component
React Native usesTextwith capital T as a core component for displaying text.Step 2: Check JSX syntax
Lowercasetextor HTML tags likedivandpare not valid in React Native JSX.Final Answer:
<Text>Hello World</Text> -> Option BQuick Check:
Use capitalized core components [OK]
Hint: React Native core components start with uppercase letters [OK]
Common Mistakes:
- Using lowercase tags like <text>
- Using HTML tags like <div> or <p>
- Confusing React Native with web React syntax
3. What will the following React Native code display on a device screen?
import React from 'react';
import { View, Text } from 'react-native';
export default function App() {
return (
Welcome!
);
}medium
Solution
Step 1: Analyze component imports
The code importsViewandTextfrom React Native core components, which render native UI elements.Step 2: Understand JSX output
TheAppfunction returns aViewcontaining aTextelement with 'Welcome!'. This displays as native UI text on the device.Final Answer:
A native screen showing the text 'Welcome!' -> Option AQuick Check:
Core components render native UI [OK]
Hint: Core components produce native UI, not web elements [OK]
Common Mistakes:
- Thinking <View> is invalid in React Native
- Expecting web HTML output
- Assuming no text will show without styles
4. Identify the error in this React Native code snippet:
import React from 'react';
import { View, Text } from 'react-native';
export default function App() {
return (
Hello
);
}medium
Solution
Step 1: Check component capitalization
React Native core components must start with uppercase letters. Here,viewis lowercase, causing an error.Step 2: Confirm correct usage
ChangingviewtoViewfixes the error.Textis correctly capitalized.Final Answer:
<view> should be capitalized as <View> -> Option DQuick Check:
Core components start uppercase [OK]
Hint: Always capitalize React Native core components [OK]
Common Mistakes:
- Using lowercase component names
- Confusing import errors with JSX errors
- Thinking multiple JSX elements need wrapping
5. You want to create a button that looks native on both iOS and Android using React Native core components. Which approach best achieves this?
hard
Solution
Step 1: Identify React Native core button component
TheButtoncore component automatically renders native buttons on iOS and Android.Step 2: Compare alternatives
Styling aViewandTextmanually won't produce native behavior. HTMLbuttonis invalid in React Native. Writing separate native code is complex and unnecessary.Final Answer:
Use the <Button> core component which renders native buttons on each platform -> Option AQuick Check:
Core components provide native UI easily [OK]
Hint: Use core <Button> for native look on both platforms [OK]
Common Mistakes:
- Trying to use HTML tags in React Native
- Manually styling views instead of using core Button
- Thinking native code is always required
Recommended
Ready to prove it?
Pass the test and this pattern moves unknown
10 questions ~5 mineasy hard
