Silly question but..... for `State` updates to wo...
# compose
d
Silly question but..... for
State
updates to work properly, do they have to be directly in a
@Composable
method? Would it still work with a non-
@Composable
wrapper method?
z
You don’t need to use Composables at all with `State`/`MutableState`. It’s very common for regular classes to define
MutableState
properties.
You don’t even need composables to observe changes, see
snapshotFlow
However, if you’re using the snapshotting infrastructure without the rest of Compose, you’ll have to apply the global snapshot yourself somehow, or use more granular snapshots.
d
That seems quite magical. My use case is to hide
State
and expose plain getters in a model.
z
Using the low-level snapshot APIs is kind of tricky. Compose will apply the global snapshot once per frame for you automatically, which is where the “magic” comes from.
d
Oh, it's global. I see.
z
It’s really common to see stuff like:
Copy code
var yourState: String by mutableStateOf("hello")
  private set
d
Thanks for explaining!
z
Anyway, if you’re using this with other Compose UI, you don’t need to even know about the global snapshot or
snapshotFlow
.