0
0
React Nativemobile~20 mins

First React Native app - Practice Problems & Coding Challenges

Choose your learning style9 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.