Skip to content

Passing search terms down to child view queries #62

Answered by groue
matiaskorhonen asked this question in Q&A
Discussion options

You must be logged in to vote

Hello @matiaskorhonen,

I'd like to pass the search terms to each child view so that they use them in their requests.

Sure, let's do that:

 struct ParentView: View {
     var foos: [Foo]
     @State private var searchText: String
 
     var body: some View {
         LazyHStack {
             ForEach(foos, id: \.id) {
-                ChildView(foo: $0).id($0.id)
+                ChildView(foo: $0, searchText: searchText).id($0.id)
             }.searchable(
                 text: $searchText,
                 prompt: "Search for a thing"
             )
         }
     }
 }
 
 struct ChildView: View {
     var foo: Foo
 
     @Query<BarRequest> private var items: [Bar]
 
-    init(foo: F…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@matiaskorhonen
Comment options

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