Am using SKIE's `Observing` and wondering if there...
# touchlab-tools
j
Am using SKIE's
Observing
and wondering if there should be way to run some swift code/create some derived state based on result of that?
I tried following for example but
onChange
not getting triggered
Copy code
Observing(someState) { value in

}.onChange(of: someState.value) { oldValue, newValue in
    print("Changing from \(oldValue) to \(newValue)")
}
f
Hi! I think that you want to do the following:
Copy code
Text("Manually updated counter: \(manuallyUpdatedCounter)")
            .collect(flow: viewModel.counter) { latestValue in
                manuallyUpdatedCounter = latestValue.intValue
            }
(If I recall correctly, onChange is supposed to be used together with things like Binding, ObservableObject, etc. bounded to the given View - which the
someState.value
most likely isn’t)
j
Yeah not too specifically focussed on using
onChange
....more how to do run that logic when it changes
I went back to using
for await
in
.task
view modifier
f
Give a try to the
collect
function.
👍 1
j
Just tried that and it worked great, thanks!