'Error: "CrashReportError: Preview is missing environment object "TabViewModel""

I am building an app in SwiftUI and I've encountered a confusing error:

CrashReportError: Preview is missing environment object "TabViewModel"

Mathematically crashed due to missing environment of type: TabViewModel. To resolve this add `.environmentObject(TabViewModel(...))` to the appropriate preview.

It's asking me to insert the modifier but doesn't mention where to put it.

This happened when I used this modifier down in my code.

.overlay(PGDetailView(animation: animation).environmentObject(tabData))

*Note: 'tabData' is used here: @EnvironmentObject var tabData: TabViewModel



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source