How to condictionly execute an action? #1918
Replies: 1 comment
-
It looks like this is a duplication of #1919 so I am going to lock this one. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Look forward for best practice for below scenario.
Let say I have a Root state holding login information and some child state.
For child state, some action need to perform after login. that is, if the user is not login, we need to show the login page for user to login, and after login.
The below is a very simple codes.
The code execute order is ③ ① ② , But for my scenario, I want ③ ① execute and ② is ignore when user is not login, How can I do that?
If can't, What is the best practice to handle this scenario. (Think about that will be many child states and in there lots of action need user login first to forward process.)
And one more question, Is there any way I can access the parent state in child state(If can, move the logic into child state is suit for me too.)
`
struct Root: ReducerProtocol {
struct State: Equatable, Codable {
var child: Child.State
var isLogin: Bool
var showLoginPage: Bool
}
}
struct Child: ReducerProtocol {
struct State: Equatable {
var isFavorite: Bool
}
}
struct ChildView: View {
let store: StoreOf
}
`
Beta Was this translation helpful? Give feedback.
All reactions