Skip to content
Discussion options

You must be logged in to vote

@zpbc007 The onChange modifier only applies to the reducer you chain onto it with. So in this case. the Reduce. If you want it to apply to the all of the child reducers, you must first combine them using CombineReducers (or in their own conformance/builder):

+CombineReducers {
   Scope(state: \.childState, action: /Action.child) {
     ChildFeature()
   }

   Reduce {state, action in
     switch action {
     case .add:
       state.parentNumber += 1
       return .none
     case .child:
       return .none
     }
   }
+}
 .onChange(of: \.parentNumber) { oldValue, newValue in
   Reduce { state, action in
     state.latestInfo = "oldValue: \(oldValue), newValue: \(newValue)"
     return .n…

Replies: 1 comment 1 reply

Comment options

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

Answer selected by zpbc007
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
Converted from issue

This discussion was converted from issue #2488 on September 28, 2023 00:18.