So I’m just wondering, but how does ambient work? ...
# compose
a
So I’m just wondering, but how does ambient work? It seems to be kinda similar to react’s context but I’m not sure if I’m right. How would I make my own ambient things, and would it be appropriate to use it for things like network?
a
yes, you've understood its nature correctly.
Context
is a bit of an occupied namespace on Android already. 🙂
Make your own with
Ambient.of
They're quite easy to make a mess of implicit dependencies with and should be used sparingly
a
And when you make an ambient, the ambient state acts global, and can be used everywhere?
Or is there a concept of providers like with react
a
there are providers.
myAmbient.Provider(value) { ComposableStuff() }
is the usage
and you can consume them with an effect:
+ambient(myAmbient)
the scope of an ambient read will recompose if the provider value changes and we can skip recomposing things in between
a
Okay, I’ll try them out and try and get the grasp of them then