Spot the bug
After 3 s, the effect calls an outdated callback if the parent passed a new one meanwhile. Which line uses the stale value?
@Composablefun Splash(onTimeout: () -> Unit) {LaunchedEffect(Unit) {delay(3_000)onTimeout()}}
Hint 1 of 1
Which onTimeout does the coroutine see after a recomposition?
Choose an answer, then open Show answer below to check it.
Show answer
- Answer: line 5
onTimeout()
The coroutine captured the first onTimeout. Use val current by rememberUpdatedState(onTimeout) and call current() here.