Challenge - 5 Problems
State and Props Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ ui_behavior
intermediate2:00remaining
What happens when a React Native component's state changes?
Consider a React Native functional component using useState. What is the immediate effect on the UI when the state is updated?
React Native
import React, { useState } from 'react'; import { Text, Button, View } from 'react-native'; export default function Counter() { const [count, setCount] = useState(0); return ( <View> <Text>{count}</Text> <Button title="Add" onPress={() => setCount(count + 1)} /> </View> ); }
Attempts:
2 left
💡 Hint
Think about what React Native does when state changes inside a component.
✗ Incorrect
When state changes, React Native re-renders the component to reflect the new state in the UI immediately.
🧠 Conceptual
intermediate2:00remaining
How do props affect a React Native component?
If a parent component passes different props to a child component, what happens to the child component?
React Native
function Greeting({ name }) {
return <Text>Hello, {name}!</Text>;
}
// Parent component changes the name prop from 'Alice' to 'Bob'Attempts:
2 left
💡 Hint
Props are how parents tell children what to show.
✗ Incorrect
When props change, React Native re-renders the child component to show the updated data.
❓ lifecycle
advanced2:00remaining
What happens if you update state directly instead of using setState in React Native?
Given a state variable declared with useState, what is the effect of modifying the state variable directly instead of calling the setter function?
React Native
const [count, setCount] = useState(0); // Incorrect update: // count = count + 1; // This line would cause an error because count is a constant // Correct update: setCount(count + 1);
Attempts:
2 left
💡 Hint
React only re-renders when you use the setter function.
✗ Incorrect
Directly changing the state variable does not notify React, so no re-render happens.
advanced
2:00remaining
How do props affect navigation between screens in React Native?
When navigating to a new screen and passing props, how does the receiving screen access those props?
React Native
navigation.navigate('Profile', { userId: 42 }); // In Profile screen component function Profile({ route }) { const { userId } = route.params; return <Text>User ID: {userId}</Text>; }
Attempts:
2 left
💡 Hint
React Navigation passes props through route parameters.
✗ Incorrect
Props passed during navigation are available in route.params on the destination screen.
🔧 Debug
expert2:00remaining
Why does this React Native component not update the UI when props change?
Look at this component. It receives a prop but does not update the displayed value when the prop changes. Why?
React Native
function Display({ value }) {
const [displayValue, setDisplayValue] = React.useState(value);
return <Text>{displayValue}</Text>;
}
// Parent changes value prop from 'Hello' to 'World'Attempts:
2 left
💡 Hint
State initialized from props does not update automatically.
✗ Incorrect
useState sets initial state only once; later prop changes do not update state unless handled explicitly.