DEV Community

Discussion on: Plumbing data with derived state in Compose

Collapse
 
gmk57 profile image
gmk57

Thanks for great "deep dive" series! Applying to typical Android apps:

State tracking works when reads are initiated from @Composable functions (not from e.g. onClick callbacks) and propagates through functions and computed properties, but not regular properties (e.g. adding backing field to _result in your From push to pull example breaks tracking).

Otherwise it's just a one-time read.

Is that understanding correct?

Looks convenient, but IMHO makes it harder to reason about code behavior. We can't say if a piece of code is "reactive" without looking above and below it in the call stack.

This is not a problem for UI code, but I'm thinking about using State in ViewModel & even deeper layers, so the call stack might be long.

Collapse
 
zachklipp profile image
Zach Klippenstein

State tracking works when reads are initiated from @Composable functions (not from e.g. onClick callbacks) and propagates through functions and computed properties, but not regular properties (e.g. adding backing field to _result in your From push to pull example breaks tracking).

Otherwise it's just a one-time read.

Is that understanding correct?

Yes.

Looks convenient, but IMHO makes it harder to reason about code behavior.

That can be true, there are definitely trade offs to this vs expressing reactivity in your types.