NavigationLink creates multiple instances of destinations in a List before selecting the row

Viewed 266

I have a List of contacts, and on clicking I want to navigate to the detail view. Here is my ListingView code:

var body: some View {
    NavigationView {
        List(viewModel.tableViewItems) { contact in
            NavigationLink(destination: ContactDetailView(viewModel: ContactDetailViewModel(contact: contact))) {
                Text(contact.fullName)
            }
        }
    }
}

This is what I found online and it works. But I found out that the view and the viewModel of the destination were getting initialised just after the List is populated, without even selecting. Is this correct or am I not understanding something properly?

0 Answers
Related