You can definitely use races as training, but they can cost you fitness if they dominate your training. That’s why most athletes lose fitness as a race season progresses.
The trick is to keep your low and high intensity within proper proportions. If your goal event is ~2 hours, then I would keep actual minutes of high intensity to about 5% of total training time. (So a ~30′ race during training should be supported by ~10 hours of base training within the same week.)
For shorter goal events (~30′), then you can probably get away with minutes of intensity representing ~10% of total training time.
You may hear people talk about an 80/20 ratio for low/high intensity proportions, but that break down comes from a “session goal approach” where an entire workout is labeled as high or low without regard to its contents.