Bird
Raised Fist0
React Nativemobile~20 mins

First React Native app - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
React Native Starter Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ ui_behavior
intermediate
2:00remaining
What will this React Native component display?
Consider this React Native component code. What text will appear on the screen when this app runs?
React Native
import React from 'react';
import { Text, View } from 'react-native';

export default function App() {
  return (
    <View>
      <Text>Hello, React Native!</Text>
    </View>
  );
}
AA blank screen with no text
BAn error because View cannot contain Text
CThe text 'Hello, React Native!' displayed on the screen
DThe text 'Hello World!' displayed on the screen
Attempts:
2 left
💡 Hint
Look at the Text component inside the View. What string does it contain?
📝 Syntax
intermediate
2:00remaining
Which option fixes the syntax error in this React Native code?
This React Native code has a syntax error. Which option fixes it so the app runs correctly?
React Native
import React from 'react';
import { Text, View } from 'react-native';

export default function App() {
  return (
    <View>
      <Text>Hello World!</Text>
    </View>
  )
}
AAdd a semicolon after the closing parenthesis of return statement
BAdd a missing closing parenthesis after the return statement
CAdd a closing semicolon after the function declaration
DReplace parentheses around JSX with curly braces
Attempts:
2 left
💡 Hint
Check if all parentheses are properly closed in the return statement.
❓ lifecycle
advanced
2:00remaining
When does the useEffect hook run in this React Native component?
Look at this React Native component using useEffect. When will the console.log run?
React Native
import React, { useEffect } from 'react';
import { Text, View } from 'react-native';

export default function App() {
  useEffect(() => {
    console.log('Component mounted');
  }, []);

  return (
    <View>
      <Text>Check console</Text>
    </View>
  );
}
AOnly once when the component first mounts
BEvery time the component re-renders
CEvery time the component unmounts
DNever, because useEffect is missing a dependency
Attempts:
2 left
💡 Hint
An empty dependency array means the effect runs only once.
❓ navigation
advanced
2:00remaining
What happens when you press this button in a React Native app using React Navigation?
Given this button code inside a React Navigation screen, what happens when the user taps it?
React Native
import React from 'react';
import { Button } from 'react-native';

export default function HomeScreen({ navigation }) {
  return (
    <Button
      title="Go to Details"
      onPress={() => navigation.navigate('Details')}
    />
  );
}
ANothing happens because onPress is not a valid prop
BThe app closes because 'Details' screen is missing
CThe button text changes to 'Details'
DThe app navigates to the screen named 'Details'
Attempts:
2 left
💡 Hint
navigation.navigate('Details') changes the screen to 'Details'.
🔧 Debug
expert
2:00remaining
Why does this React Native app crash on startup?
This React Native app crashes immediately. What is the cause?
React Native
import React from 'react';
import { Text, View } from 'react-native';

export default function App() {
  console.log('App rendered');
  return (
    <View>
      <Text>Hello</Text>
    </View>
  );
}
ACode after return statement is unreachable causing a syntax error
BMissing import for console causes crash
CView component cannot contain Text component directly
DFunction App is missing a return statement
Attempts:
2 left
💡 Hint
Code after return inside a function is unreachable and invalid.

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

  1. 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.
  2. Step 2: Compare with other components

    Text displays text, but View is for layout and grouping.
  3. Final Answer:

    To act as a container for other components and layout -> Option A
  4. 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

  1. Step 1: Check React import

    React is imported as default from 'react', so import React from 'react'; is correct.
  2. 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.
  3. Final Answer:

    import React from 'react'; import { View, Text } from 'react-native'; -> Option A
  4. 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

  1. Step 1: Analyze the returned JSX

    The App function returns a View containing a Text component with the string 'Hello, React Native!'.
  2. Step 2: Understand rendering behavior

    React Native will display the text inside the Text component on the screen inside the View.
  3. Final Answer:

    The text 'Hello, React Native!' displayed on the screen -> Option C
  4. 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

  1. 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.
  2. Step 2: Check React Native rules

    View does not require a style prop to work. Semicolons are optional in JavaScript.
  3. Final Answer:

    No error; the code is correct and will run -> Option B
  4. 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

  1. 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.
  2. 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.
  3. Final Answer:

    { flex: 1, justifyContent: 'center', alignItems: 'center' } -> Option D
  4. Quick Check:

    Flexbox center with flex:1 [OK]
Hint: Use flex:1 with justifyContent and alignItems center [OK]
Common Mistakes:
  • Using padding or margin to center content
  • Forgetting flex:1 to fill screen
  • Using wrong flexDirection or positioning
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard