Skip to content

BindingReducer does not observe nested ViewState properties in @ObservableState #3560

Answered by mbrandonw
FpRaArNkK asked this question in Q&A
Discussion options

You must be logged in to vote

Hi @FpRaArNkK, this is to be expected. If you were to use _printChanges() to see the actions being sent to your reducer you will find that it's a binding action with the key path \.viewState. The sub-key path of the actual field you are mutating is not known to the library at all. All that is known is that viewState was mutated.

An alternative way to listen for changes is to use the onChange reducer operator:

Reduce {  }
  .onChange(of: \.viewState.photoPickerItem) {  }

This is mentioned in the docs. Another alternative would be to not bundle the state into a ViewState struct and have it flattened directly in the feature state.

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@FpRaArNkK
Comment options

Answer selected by FpRaArNkK
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants