What is the main component used to display text in a React Native app?
The Text component is used to display text in React Native. It works like a label or paragraph in web pages.
Click to reveal answer
beginner
How do you create a simple React Native component?
You create a function that returns JSX code. For example:<br><code>function Hello() { return <Text>Hi!</Text>; }</code>
Click to reveal answer
beginner
What is the purpose of the View component in React Native?
The View component is like a container or box. It groups other components and helps with layout and styling.
Click to reveal answer
beginner
How do you run your first React Native app on a device or emulator?
You use the command npx react-native run-android for Android or npx react-native run-ios for iOS after starting the Metro bundler.
Click to reveal answer
beginner
Why do React Native apps use JSX syntax?
JSX lets you write UI code that looks like HTML but works in JavaScript. It makes building interfaces easier and clearer.
Click to reveal answer
Which React Native component is used to group other components and control layout?
AButton
BText
CView
DImage
✗ Incorrect
The View component acts as a container to group and layout other components.
What command starts the Metro bundler in a React Native project?
Anpm start
Breact-native run
Cnpm run metro
Dnpx react-native start
✗ Incorrect
The command npx react-native start starts the Metro bundler which serves your app's JavaScript.
In React Native, which syntax allows you to write UI code inside JavaScript?
AJSX
BCSS
CHTML
DXML
✗ Incorrect
JSX is a syntax extension that lets you write UI code inside JavaScript.
Which component would you use to display a simple text message?
AText
BView
CScrollView
DTouchableOpacity
✗ Incorrect
The Text component is designed to display text content.
How do you run a React Native app on an Android emulator?
Anpx react-native run-ios
Bnpx react-native run-android
Cnpm run android
Dreact-native start android
✗ Incorrect
Use npx react-native run-android to build and run the app on an Android emulator.
Describe the basic steps to create and run your first React Native app.
Think about writing UI code, starting the server, and launching the app.
You got /4 concepts.
Explain why JSX is helpful when building React Native apps.
Consider how writing UI code inside JavaScript helps developers.
You got /4 concepts.
Practice
(1/5)
1. What is the main purpose of the View component in a React Native app?
easy
A. To act as a container for other components and layout
B. To display text on the screen
C. To handle user input events
D. To fetch data from the internet
Solution
Step 1: Understand the role of View
The View component is like a box that holds other components and helps arrange them on the screen.
Step 2: Compare with other components
Text displays text, but View is for layout and grouping.
Final Answer:
To act as a container for other components and layout -> Option A
Quick Check:
View = container [OK]
Hint: Remember: View is like a box holding things [OK]
Common Mistakes:
Confusing View with Text
Thinking View handles user input
Assuming View fetches data
2. Which of the following is the correct way to import React and React Native components in your first app?
easy
A. import React from 'react'; import { View, Text } from 'react-native';
B. import { React, View, Text } from 'react-native';
C. import React, { View, Text } from 'react';
D. import View, Text from 'react-native';
Solution
Step 1: Check React import
React is imported as default from 'react', so import React from 'react'; is correct.
Step 2: Check React Native components import
Components like View and Text are named exports from 'react-native', so import { View, Text } from 'react-native'; is correct.
Final Answer:
import React from 'react'; import { View, Text } from 'react-native'; -> Option A
Quick Check:
Default React + named components import [OK]
Hint: React default, components named import [OK]
Common Mistakes:
Importing React components from 'react-native' incorrectly
Using default import for View and Text
Missing curly braces for named imports
3. What will the following React Native code display on the screen?
import React from 'react';
import { View, Text } from 'react-native';
export default function App() {
return (
Hello, React Native!
);
}
medium
A. An error because View is missing a style
B. A blank screen with no text
C. The text 'Hello, React Native!' displayed on the screen
D. The text 'Hello, React Native!' but inside a button
Solution
Step 1: Analyze the returned JSX
The App function returns a View containing a Text component with the string 'Hello, React Native!'.
Step 2: Understand rendering behavior
React Native will display the text inside the Text component on the screen inside the View.
Final Answer:
The text 'Hello, React Native!' displayed on the screen -> Option C
Quick Check:
Text inside View renders as visible text [OK]
Hint: Text inside View shows on screen [OK]
Common Mistakes:
Thinking style is required to show text
Confusing View with Button
Expecting an error 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 World
)
}
medium
A. Missing semicolon after return statement
B. No error; the code is correct and will run
C. The JSX is missing parentheses around the return value
D. The View component must have a style prop
Solution
Step 1: Check JSX syntax
The JSX inside the return is wrapped in parentheses, which is optional but allowed. The code uses valid JSX syntax.
Step 2: Check React Native rules
View does not require a style prop to work. Semicolons are optional in JavaScript.
Final Answer:
No error; the code is correct and will run -> Option B
Quick Check:
Valid JSX and React Native code [OK]
Hint: JSX parentheses optional; style not required [OK]
Common Mistakes:
Thinking style prop is mandatory
Expecting semicolons are required
Assuming parentheses are always needed
5. You want to create a simple React Native app that shows the text 'Welcome!' centered both vertically and horizontally on the screen. Which style object should you apply to the View component to achieve this?
hard
A. { padding: 10, margin: 10 }
B. { flexDirection: 'row', justifyContent: 'flex-start', alignItems: 'flex-start' }
C. { position: 'absolute', top: 0, left: 0 }
D. { flex: 1, justifyContent: 'center', alignItems: 'center' }
Solution
Step 1: Understand centering in React Native
To center content vertically and horizontally, the container needs to fill the screen with flex: 1 and use justifyContent: 'center' for vertical centering and alignItems: 'center' for horizontal centering.
Step 2: Evaluate each style option
{ flex: 1, justifyContent: 'center', alignItems: 'center' } uses the correct flexbox properties for centering. Options A, B, and D do not center content both ways.