Hi all ๐ Been reading about CompositionLocal and Iโm trying to understand when you would use a static CompositionLocal over a dynamic one. Is there any guidance on this anywhere? From my understanding a static CompositionLocal will cause the entire tree below to recompose, which seems worse than always just recomposing the Composable(s) using it
z
Zach Klippenstein (he/him) [MOD]
03/17/2021, 3:37 PM
a static CompositionLocal will cause the entire tree below to recompose, which seems worse than always just recomposing the Composable(s) using it
Exactly, so static locals are intended for when the value will never change, or only change very rarely. E.g. the
Context
is provided via a static local, because the
Context
is strongly associated to the entire composition (itโs used to create the android views that host it) and it can never change for a given composition.