Challenge - 5 Problems
Default Props Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ ui_behavior
intermediate2:00remaining
What will be displayed when no props are passed?
Consider this React Native component with default props. What text will appear if the component is rendered without any props?
React Native
import React from 'react'; import { Text } from 'react-native'; const Greeting = ({ name }) => { return <Text>Hello, {name}!</Text>; }; Greeting.defaultProps = { name: 'Friend' }; export default Greeting;
Attempts:
2 left
💡 Hint
Look at the defaultProps object and see what value is set for name.
✗ Incorrect
If no name prop is passed, React Native uses the defaultProps value 'Friend', so the text shows 'Hello, Friend!'.
📝 Syntax
intermediate2:00remaining
Identify the correct way to set default props in a functional component
Which option correctly sets default props for a React Native functional component named Button?
React Native
import React from 'react'; import { Text, TouchableOpacity } from 'react-native'; const Button = ({ label }) => { return <TouchableOpacity><Text>{label}</Text></TouchableOpacity>; };
Attempts:
2 left
💡 Hint
defaultProps should be an object with keys matching prop names.
✗ Incorrect
defaultProps must be an object where keys are prop names and values are default values. Option B follows this correctly.
❓ lifecycle
advanced2:00remaining
When are default props applied in React Native functional components?
At what point in the component lifecycle are default props applied to a React Native functional component?
Attempts:
2 left
💡 Hint
Think about when the component receives its props to use inside the function.
✗ Incorrect
React applies defaultProps before calling the component function, so missing props have default values inside the function.
🔧 Debug
advanced2:00remaining
Why does this component show 'undefined' instead of the default prop?
This React Native component tries to use default props but shows 'undefined' when no prop is passed. Why?
React Native
import React from 'react'; import { Text } from 'react-native'; const Welcome = ({ user }) => { return <Text>Welcome, {user}!</Text>; }; // Incorrect default props Welcome.defaultProps = { user: 'Guest' }; export default Welcome;
Attempts:
2 left
💡 Hint
Check the type assigned to defaultProps.
✗ Incorrect
defaultProps must be an object. Assigning a function to defaultProps does not set default values, so 'user' remains undefined.
🧠 Conceptual
expert2:00remaining
How do default props interact with destructured parameters with default values?
Given this React Native component, what will be the output if rendered with no props?
React Native
import React from 'react'; import { Text } from 'react-native'; const Info = ({ message = 'Hello' }) => { return <Text>{message}</Text>; }; Info.defaultProps = { message: 'Hi' }; export default Info;
Attempts:
2 left
💡 Hint
defaultProps are applied to the props object before destructuring happens inside the component function.
✗ Incorrect
React applies defaultProps before calling the component function, setting message to 'Hi'. The destructuring default 'Hello' is not used because message is already defined as 'Hi'.