Skip to content

Questions about Nested State usage #2984

Answered by kevinanderson7
mamboer asked this question in Q&A
Discussion options

You must be logged in to vote

That's one way to go about it. Or you could declare a mutating func as part of ViewBFeat.State and then call it from ViewAFeat. Something like this:

@Reducer
struct ViewAFeat {
  @ObservableState
  struct State: Equatable {
    var viewB: ViewBFeat.State = .init()
    var x: Float = 0
  }
  
  enum Action {
    case viewB(ViewBFeat.Action)
    case reset
  }
  
  var body: some ReducerOf<Self> {
    Scope(state: \.viewB, action: \.viewB) {
      ViewBFeat()
    }
    Reduce { state, action in
      switch action {
      case .reset:
        state.x = 0
        // update ViewBFeat's state directly or with mutating func
        // state.viewB.y = 0
        state.viewB.reset()
        return .

Replies: 1 comment 6 replies

Comment options

You must be logged in to vote
6 replies
@kevinanderson7
Comment options

@mamboer
Comment options

@kevinanderson7
Comment options

Answer selected by mamboer
@mamboer
Comment options

@kevinanderson7
Comment options

@Narsail
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants