At the moment, the current docs recommend state ho...
# compose
j
At the moment, the current docs recommend state hoisting for state management, but I fear that state hoisting can be difficult if a specific state must be hoisted up multiple levels. Having learned Flutter before Jetpack Compose, I liked the Provider approach, and Jetpack Compose seems to have something similar in the form of
CompositionLocal
and
CompositionLocalProvider
. My question is, why are these 2 not recommended for state management?
j
Interesting. I did figure that
CompositionLocal
would be more appropriate for things more global to an app. I'm still not sure if I'm satisfied with lots of state hoisting if it happens, but I guess that's just the reality of Jetpack Compose. Anyways, thank you for the thread!
a
State hoisting just refers to a parent providing state to a child as opposed to the child implementing it as private state. Whether it's provided via parameters, CompositionLocals, or any other mechanism is an implementation detail
CompositionLocals, Flutter Providers and React Contexts all share the same advantages and drawbacks here. If one works well for you in one environment, it will work equally well in another and encounter the same design challenges.
j
I see, thank you for the explanation!