I know the general rule of thumb is to not overuse...
# compose
c
I know the general rule of thumb is to not overuse composition locals. Would analytics be an "okay" reason to use them or should I just properly keep passing them down into all of my composables?
j
They’re discouraged because they create implicit dependencies you need to fake out (or provide) in tests and previews. It’s going to be a judgement call based on how frequently you’re passing it around and how often it’s being updated. imo if something is infrequently updated but used by many composables at varying levels of nesting, it’s usually a good candidate. We use them for things like theme, unit preferences (kg/lb), feature flags etc. In a codebase of 400+ composables, we use 5 composition locals
a
what's the behavior if the CompositionLocal in question hasn't been set/it has its default value?
if the answer to that is, "something reasonable" then you may be in good shape
c
I think I'm actually going to try to track all of my analytics in my ViewModel