Challenge - 5 Problems
StyleSheet Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
📝 Syntax
intermediate2:00remaining
What is the output of this code snippet using StyleSheet.create?
Consider this React Native code snippet:
What will be logged to the console?
import { StyleSheet } from 'react-native';
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: 'blue'
}
});
console.log(typeof styles.container);What will be logged to the console?
React Native
import { StyleSheet } from 'react-native'; const styles = StyleSheet.create({ container: { flex: 1, backgroundColor: 'blue' } }); console.log(typeof styles.container);
Attempts:
2 left
💡 Hint
Think about what StyleSheet.create returns for each style key.
✗ Incorrect
StyleSheet.create returns an object where each key is a style reference object, so typeof styles.container is 'object'.
❓ ui_behavior
intermediate2:00remaining
Which option correctly applies a style created with StyleSheet.create?
Given this style:
Which of these React Native Text components will render the text in red color and font size 20?
const styles = StyleSheet.create({
text: {
color: 'red',
fontSize: 20
}
});Which of these React Native Text components will render the text in red color and font size 20?
React Native
const styles = StyleSheet.create({
text: {
color: 'red',
fontSize: 20
}
});Attempts:
2 left
💡 Hint
Remember how to pass a style object in JSX.
✗ Incorrect
The style prop expects an object or array of objects, so style={styles.text} is correct. Passing a string or double braces is incorrect.
❓ lifecycle
advanced2:00remaining
What happens if you create a new StyleSheet inside a component's render method?
Consider this React Native component:
What is the impact of creating the StyleSheet inside the component function?
function MyComponent() {
const styles = StyleSheet.create({
box: { width: 100, height: 100, backgroundColor: 'green' }
});
return ;
}What is the impact of creating the StyleSheet inside the component function?
React Native
function MyComponent() {
const styles = StyleSheet.create({
box: { width: 100, height: 100, backgroundColor: 'green' }
});
return <View style={styles.box} />;
}Attempts:
2 left
💡 Hint
Think about how often the component renders and what happens each time.
✗ Incorrect
Calling StyleSheet.create inside the component creates a new style object each render, which can cause unnecessary work and reduce performance.
advanced
2:00remaining
How does StyleSheet.create affect dynamic styling during navigation transitions?
You have two screens in a React Native app. Each screen uses StyleSheet.create to define styles. If you want to change a style dynamically during navigation (like changing background color based on route params), which approach works best?
Attempts:
2 left
💡 Hint
StyleSheet.create is for fixed styles, think about how to handle changes.
✗ Incorrect
StyleSheet.create is optimized for static styles. For dynamic changes, use inline styles or state variables combined with styles.
🔧 Debug
expert2:00remaining
Why does this StyleSheet.create code cause a runtime error?
Look at this code:
When applying styles.button, the app crashes. What is the cause?
const styles = StyleSheet.create({
button: {
backgroundColor: 'blue',
padding: 10,
borderRadius: '5'
}
});When applying styles.button, the app crashes. What is the cause?
React Native
const styles = StyleSheet.create({
button: {
backgroundColor: 'blue',
padding: 10,
borderRadius: '5'
}
});Attempts:
2 left
💡 Hint
Check the data types expected for style properties.
✗ Incorrect
React Native style properties like borderRadius expect numbers, not strings. Using '5' (string) causes a runtime error.