title: SwiftUI - how to respond to TextField onCommit in an other View?
body: <p>I made a <code>SearchBarView</code> view to use in various other views (for clarity, I removed all the layout modifiers, such as color and padding):</p>
  <pre><code>struct SearchBarView: View {
      @Binding var text: String
      @State private var isEditing = false
      
      var body: some View {
          HStack {
              TextField(&quot;Search…&quot;, text: $text, onCommit: didPressReturn)
                   .overlay(
                      HStack {
                          Image(systemName: &quot;magnifyingglass&quot;)
                              .frame(minWidth: 0, maxWidth: .infinity, alignment: .leading)
                          
                          if isEditing {
                              Button(action: {
                                  self.text = &quot;&quot;
                              }) {
                                  Image(systemName: &quot;multiply.circle.fill&quot;)
                              }
                          }
                      }
                  )
      }
      
      func didPressReturn() {
          print(&quot;did press return&quot;)
      }
  }
  </code></pre>
  <p>It looks and works great to filter data in a <code>List</code>.</p>
  <p>But now I'd like to use the <code>SearchBarView</code> to search an external database.</p>
  <pre><code>struct SearchDatabaseView: View {
      @Binding var isPresented: Bool
      @State var searchText: String = &quot;&quot;
  
      var body: some View {
          NavigationView {
              VStack {
                  SearchBarView(text: $searchText)
                  // need something here to respond to onCommit and initiate a network call.
  
              }
              .navigationBarTitle(&quot;Search...&quot;)
              .navigationBarItems(trailing:
                  Button(action: { self.isPresented = false })  {
                      Text(&quot;Done&quot;)
              })
          }
      }
  }
  </code></pre>
  <p>For this, I only want to start the network access when the user hits return. So I added the <code>onCommit</code> part to <code>SearchBarView</code>, and the <code>didPressReturn()</code> function is indeed only called when tapping return. So far, so good.</p>
  <p>What I don't understand is how <code>SearchDatabaseView</code> that contains the <code>SearchBarView</code> can respond to <code>onCommit</code> and initiate the database searh - how do I do that?</p>