Rafs
08/29/2023, 3:55 PM@Composable
fun StyledText(
text: State<String>,
) {
Text(text = text.value)
}
Colton Idle
08/29/2023, 4:26 PMRafs
08/29/2023, 4:27 PMStylianos Gakis
08/29/2023, 4:41 PM() -> T
instead.
The reason is simple, you still get the benefit of deferred reads when you need that.
But () -> T
also allows you to pass a normal non-state object.
If you use State<String>
instead as you show above, and you don’t have a state at some call-site, you’d need to turn your normal parameter into a state just to pass into this clunky API. Don’t do it.jefbit
08/29/2023, 6:11 PMZach Klippenstein (he/him) [MOD]
08/29/2023, 6:56 PMState
types, no, for the reasons above.vide
08/30/2023, 6:39 AMState<T>
as a parameter. It's just that passing () -> T
is better for the benefits mentioned by Stylianos & Zach.MR3Y
08/30/2023, 10:14 AM@Composable
fun StyledText(text: String) {
....
}
But these 2 are deferring reads:
@Composable
fun StyledText(text: State<String>) {
....
}
@Composable
fun StyledText(text: () -> String) {
....
}
Right?vide
08/30/2023, 10:14 AM