https://kotlinlang.org logo
#compose
Title
# compose
a

Ali Albaali

01/15/2021, 3:02 PM
Is there difference between passing composable emptyContent VS null ?
Copy code
@Composable
fun SomeComposable(content : @Composable (() -> Unit)? = null) {}
Copy code
@Composable
fun OtherComposable(content : @Composable () -> Unit = emptyContent()) {}
a

Adam Powell

01/15/2021, 3:39 PM
Use nullable parameters if the composable needs to test the parameter's value and behave differently if the parameter is null. Comparing against
emptyContent()
isn't reliable for such use cases.
If you don't need this kind of branching behavior, prefer
emptyContent()
and non-nullable.
The difference between the two in the function signature sets expectations for the caller.
a

Ali Albaali

01/15/2021, 4:06 PM
I see. Thanks
2 Views