Challenge - 5 Problems
Recomposition Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ ui_behavior
intermediate2:00remaining
What triggers recomposition in Jetpack Compose?
In Jetpack Compose, which of the following changes will cause a composable function to recompose?
Attempts:
2 left
💡 Hint
Think about what Compose observes to know when to update the UI.
✗ Incorrect
Compose tracks State variables used inside composables. When a State changes, Compose triggers recomposition to update the UI. Local variables or constants do not trigger recomposition.
❓ lifecycle
intermediate2:00remaining
How does recomposition affect performance?
Which statement best describes how recomposition impacts app performance in Jetpack Compose?
Attempts:
2 left
💡 Hint
Think about how Compose optimizes UI updates.
✗ Incorrect
Compose recomposes only the composables affected by State changes, avoiding full UI redraws and improving performance.
🔧 Debug
advanced2:00remaining
Why does this composable not recompose when State changes?
Consider this code snippet:
@Composable
fun Greeting(name: String) {
Text(text = "Hello, $name!")
}
val userName = mutableStateOf("Alice")
// In UI
Greeting(name = userName.value)
Why might the UI not update when userName.value changes?
Attempts:
2 left
💡 Hint
Think about how Compose tracks State changes through parameters.
✗ Incorrect
Passing only the value of a State variable does not let Compose track changes. The composable must receive a State or be called with a value that changes to trigger recomposition.
🧠 Conceptual
advanced2:00remaining
What is the role of remember in recomposition?
In Jetpack Compose, what does the remember function do during recomposition?
Attempts:
2 left
💡 Hint
Think about how to keep values stable during UI updates.
✗ Incorrect
remember keeps a value in memory across recompositions so it is not recreated each time the composable runs.
expert
2:00remaining
How does recomposition interact with navigation state?
In a Jetpack Compose app using Navigation Compose, what happens to composables when navigating between screens regarding recomposition?
Attempts:
2 left
💡 Hint
Consider the lifecycle of composables in navigation stacks.
✗ Incorrect
When navigating away, the previous screen's composables are removed from the composition and do not recompose until navigated back.