ForEachStore with Simple SwiftUI button Inside

Good day. I'm new to composable architecture and Im currently trying to make a list of cards by using ForEachStore because I want to pass the current state to the detail screen of the list and also trying to implement the pagination for the list with ForEachStore

  var body: some View {
    WithViewStore(, observe: ViewState.init) { (viewStore: ViewStore<ViewState, PhotoListFeature.Action>) in
      NavigationStack {
        ScrollView {
          LazyVStack {
              state: \.photoList,
            )) { _ in
              Button {
              } label: {
              }.task {

        .refreshable {
          Task {
            state: \.destination,
            action: PhotoListFeature.Action.destination
          state: /PhotoListFeature.Destination.State.showPhotoDetail,
          action: PhotoListFeature.Destination.Action.showPhotoDetail
        ) { store in
          PhotoDetailView(store: store)
        .task {

but unfortunately, I'm getting these errors:

Hi @vlainvaldez, there are a number of problems in the code you posted. First, you are ignoring the argument of the trailing closure of ForEachStore:

)) { _ in

That argument is the store that encapsulates the runtime for that row, and is typically passed on to a row view.

Second, you are using $0 in the action closure of Button, but that closure doesn't take any arguments.

You would probably have better luck if you moved the Button to its own view with its own TCA feature. It could be called PhotoRow, and that's the view that can have the buttonTapped action and the .task action. Just a suggestion.

1 Like

Thank you for this suggestion. I appreciate it!

I created a separate tca feature for the button for it to live in its own space rather than putting them all inside the Foreach store. Thank you! @mbrandonw