I don't know if this is good practice, but what I do is have my outer view with the query:
struct OuterView: View {
@Query var data: [Item]
var body: some View {
MiddleView(date: data)
}
}
Then Have a MiddleView which has a @State and calls a InnerView:
struct MiddleView: View {
@State var data: [Item]
var body: some View {
InnerView(date: $data)
}
}
And the InnerView is:
struct InnerView: View {
@Binding var data: [Item]
var body: some View {
TextEditor(text: $date.name)
}
}
This works because the SwiftData models are classes and are reference objects.
This is what I do, don't know if it is best practice, but this way you don't have to use the modelContext.