Home IOS Development ios – Why onChange shouldn’t be working for baby view attributes

ios – Why onChange shouldn’t be working for baby view attributes

0
ios – Why onChange shouldn’t be working for baby view attributes

[ad_1]

I’ve quite simple two views. ContentView and ChildView.
I wish to observe baby view VM attributes in ContentView VIA .onChange

class ContentViewVM: ObservableObject {
    @Printed var childVM = ChildVM()
}

struct ContentView: View {
    
    @StateObject var contentVM = ContentViewVM()
    
    var physique: some View {
        ChildView(viewModel: contentVM.childVM)
            .onChange(of: contentVM.childVM.isPaymentPresented) { newValue in
                    print("Change Noticed")
            }            
    }
}

struct ChildView: View {
    @StateObject var viewModel: ChildVM
    var physique: some View {
        Button("Deep Stage Set off") {
            viewModel.isPaymentPresented.toggle()
            print("Deep Stage Triggered: (viewModel.isPaymentPresented)")
        }
    }
}

class ChildVM: ObservableObject {
    @Printed var isPaymentPresented: Bool = false
}

After I click on, ChildView Button.

‘Deep Stage Triggered: true’ is printed however ‘Change Noticed’ shouldn’t be printing.

[ad_2]

LEAVE A REPLY

Please enter your comment!
Please enter your name here