In my main view I have the following variable:
@State private var link = "https://www.google.com"
The view has two children that contain the variable's binding:
@Binding var text: String
, initialized like this: Child(text: $link)
Child 1 updates the variable, the parent receives the change, but Child 2 still keeps the first value
If you want a view to rebuild itself, you need to modify its state, environment object or observed object; those are the only things the view subscribes to. If you just modify a binding the view has no way of knowing it needs to rebuild. You should have the binding modify as a side effect either the environment, state or observed object of the view. Since you have some shared state between children and a parent view and @EnvironmentObject
seems like the right place to do it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With