Strange typing of State #1982
-
Hi all! FEATURE
SWIFTUI VIEW
This code works but I cannot understand why Can someone give me an hint on this? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hey @Nerkyator! The type of the In some ways, it is functionally similar to scoping to a smaller store that you're observing. You can check the "Performance" article where a dedicated type ( Please also note that you can derive a binding by pointing to a specific property of the viewStore.binding(get: \.selectedScreen, send: ContentViewFeature.Action.selectedScreenChanged) The variant without |
Beta Was this translation helpful? Give feedback.
Hey @Nerkyator! The type of the
ViewStore
's state is the type of the "observed" state. In your case, you're observing\.selectedScreen
only, so the value thatViewStore
will observe and present will be aScreen
.In some ways, it is functionally similar to scoping to a smaller store that you're observing.
When you replace by
{ $0 }
, you observe the whole state, so theViewStore
presents aContentViewFeature.State
.You can check the "Performance" article where a dedicated type (
ViewState
) is also used. In your case, observingScreen
only was the optimal choice (even if in this case, it's be similar to observing the whole state!).Please also note that you can derive a binding by pointing to…