Replies: 2 comments
-
Hi @appfrosch, the disabled state should be derivable from You will also want to heavily reduce the amount of state you are observing. Right now you are observing everything in WithViewStore(self.store, observe: { $0 }) { viewStore in …even though it doesn't seem like you are currently using any of the state. This is not going to be performant and going to become problematic over time. Read our article on this topic to understand how to fix this. |
Beta Was this translation helpful? Give feedback.
-
That’s awesome, thanks. That was exactly the push in the right direction. Here’s what I came up with: struct ItemListDomain: Reducer {
struct State: Equatable {
//…
var addingItemIsValid: Bool? {
if case let .addNewItem(itemState) = destination {
return itemState.item.title.isEmpty
}
return nil
}
}
//…
} I can the use it like this: .disabled(viewStore.addingItemIsValid ?? false) I know that I have so far ignored optimizing state observation, I will really have to educate myself on that. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I am using the
prerelease/1.0
branch.Consider a list I want to add an item to via a
.sheet
. I want to enable adding only if a title has been provided, thus disabling the confirm button ifitem.title
isnil
.My problem has to do with scope I guess: I am calling
.sheet
on the parent, display the child with its viewstore and append a.toolbar
to that view. The confirm button of this toolbar should only be active if a title is given for the item.How can I scope correctly here/find out about that state in the parent?
Any hints on a relevant episode on this would be helpful!
Here's the
.sheet
modifier for that:And here's a running project for this:
Beta Was this translation helpful? Give feedback.
All reactions