Is that okay to do something like this or should I...
# compose
y
Is that okay to do something like this or should I just wrap it in an if(list.isNotEmpty()) ? 2 or 3 years ago I saw something bad about return in composable, not sure where we are at right now
Copy code
@Composable
fun UserStatStrip(stats: ImmutableList<StatStripItem>, modifier: Modifier = Modifier) {
    if (stats.isEmpty()) return

    Row(
        modifier = modifier
            .fillMaxWidth()
            .background(MaterialTheme.colorScheme.surface),
    ) {
    ....
}
e
Don't use early return in composables, it breaks recomposition. Unless something changed recently, this will introduce hard to reproduce bugs
t
I think they fixed the problems with early returns no?
e
Great if this was fixed, would appreciate some sources though 😄
t
e
Thanks, that looks promising, although that bug has been re-opened multiple times, it seems there are still some related bugs being opened, perhaps it's still a good idea to avoid early returns (in composables) if possible.
t
This is from 2023, so probably there's already fixes to the other ones. I remember having a ton of issues in the early days of compose with early returns but there's already quite a long time they don't give me a problems anymore. In any case, that's my personal experience, I just prefer to not have a extra nesting but doing the opposite also works fine, so we can both do what we are more comfortable with 😄
e
I agree with you, I would love to use early returns as well 😄 Just that I am still worried as I had a lot of crashes/bugs in the early days as well
👍 1
y
Thanks both of you, well I think i’ll use the if(stats.isNotEmpty()) as I still fear the weird bugs coming 2 or 3 weeks later and not remembering this