Filip Stanis
01/24/2022, 6:37 PM@Composable
fun MyButton(onClick: () -> Unit) {
Button(onClick = onClick) { ... }
}
// vs
@Composable
fun MyButton(onClick: () -> Unit) {
Button(onClick = { onClick() } { ... }
}
(this is probably a more general kotlin question, but I see both patterns in compose code and it's unclear if one is better / worse than the other)Zach Klippenstein (he/him) [MOD]
01/24/2022, 6:53 PMAdam Powell
01/24/2022, 10:16 PMZach Klippenstein (he/him) [MOD]
01/24/2022, 11:41 PMAdam Powell
01/25/2022, 12:09 AMZach Klippenstein (he/him) [MOD]
01/25/2022, 12:17 AMFunction0
to a Function1
Colton Idle
01/25/2022, 5:26 AMblah
works
• `blah()`works
• {blah()}
works
/shruggie. need to get more comfortable with lambdas/functions in kotlin 😄Abhinav Suthar
01/25/2022, 10:15 AMZach Klippenstein (he/him) [MOD]
01/26/2022, 2:39 AMAbhinav Suthar
01/26/2022, 7:44 AM@Composable
fun Parent(paramA: String, onChildBClick: (String) -> Unit){
ChildA(paramA)
ChildB( onClick = { onChildBClick("string") })
}
Now assume on re-composition, paramA changes so Parant function will re-compose. So ChildA will get re-composed because paramA has been updated. And if I understand it correctly, ChildB will also recompose because onClick lambda function has been updated (new lambda created). I want to prevent this extra recomposition of ChildB by wrapping the lambda inside remember block or should I not be worried about it if it makes no big difference?Zach Klippenstein (he/him) [MOD]
01/26/2022, 5:47 PMAdam Powell
01/26/2022, 8:02 PM