0
0
React Nativemobile~20 mins

Text component in React Native - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Text Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
ui_behavior
intermediate
2:00remaining
What will this Text component display?
Consider this React Native code snippet:
import React from 'react';
import { Text } from 'react-native';

export default function App() {
  return Hello World;
}

What will the user see on the screen?
React Native
import React from 'react';
import { Text } from 'react-native';

export default function App() {
  return <Text style={{fontWeight: 'bold', fontSize: 20}}>Hello World</Text>;
}
AThe text 'Hello World' in bold and larger font size
BThe text 'Hello World' in normal font weight and default size
CAn error because fontWeight cannot be 'bold' in React Native
DThe text 'Hello World' but invisible because no color is set
Attempts:
2 left
💡 Hint
Check the style properties applied to the Text component.
📝 Syntax
intermediate
2:00remaining
Which option correctly renders multi-line text in React Native?
You want to display this text with line breaks:
Hello
World

Which code snippet will show the text on two lines?
A<Text>Hello\nWorld</Text>
B
&lt;Text&gt;Hello
World&lt;/Text&gt;
C
&lt;Text&gt;Hello{'
'}World&lt;/Text&gt;
D<Text>{'Hello\nWorld'}</Text>
Attempts:
2 left
💡 Hint
In JSX, how do you insert a newline character inside text?
lifecycle
advanced
2:00remaining
What happens if you update state inside a Text component's onPress?
Given this code:
const [count, setCount] = React.useState(0);

return  setCount(count + 1)}>Count: {count};

What will happen when the user taps the text multiple times?
React Native
const [count, setCount] = React.useState(0);

return <Text onPress={() => setCount(count + 1)}>Count: {count}</Text>;
AThe number after 'Count:' increases by 1 each tap
BThe text does not change because Text cannot handle onPress
CThe app crashes because setCount is called inside Text
DThe number resets to 0 after each tap
Attempts:
2 left
💡 Hint
Text supports onPress and state updates cause re-render.
🔧 Debug
advanced
2:00remaining
Why does this Text component not show the expected color?
Look at this code:
Hello
World

Both texts appear black on the screen. Why?
React Native
<Text style={{color: 'red', fontSize: 18}}>Hello</Text>
<Text style={{color: 'blue'}}>World</Text>
AReact Native does not support color style on Text components
BThe parent component has a style overriding text color to black
CThe color property must be set using 'textColor' instead of 'color'
DThe styles are correct; the problem is the device's dark mode
Attempts:
2 left
💡 Hint
Check if any parent container styles affect text color.
🧠 Conceptual
expert
3:00remaining
How does React Native handle nested Text components?
Consider this code:

  Hello World

What will be the visual result on the screen?
React Native
<Text style={{fontSize: 20}}>
  Hello <Text style={{fontWeight: 'bold'}}>World</Text>
</Text>
AOnly 'Hello' is shown, 'World' is ignored inside nested Text
BBoth 'Hello' and 'World' are bold and font size 20
CThe entire text is normal weight and default font size
DThe word 'Hello' is normal weight, 'World' is bold, both font size 20
Attempts:
2 left
💡 Hint
Nested Text inherits styles but can override some properties.