is there a recommended way as to whether you shoul...
# compose
o
is there a recommended way as to whether you should always initialise Composable’s parameters to empty or null or
{}
?
s
o
but what’s more recommended, do you initialize them all ?
s
Depends on your use case. • Are they mandatory? Then no default parameter and non-null. • Are the mandatory but have a sane default? Non-null and provide that default as a lambda. Just like scaffold for material2 does for snackbar. • Can they simply be omitted and have nothing be emitted on the UI? default to = {}. • Can they simply be omitted and have nothing be emitted on the UI and you want to for some reason check if that slot is empty (like in the linked post)? Nullable and default to
= null
to be able to do the
!= null
check. Material 3 seems to favor going with non-null but empty, as seen here so I’d say it’s safe to do so if you please. But the type you expose really conveys which of these things I mentioned above are the case for your composable
o
thanks a lot man
that is very comprehensive