Spaying is the most effective way to stop a female cat from spraying.
Spraying is hormone-driven, and spaying removes the source of those hormones. Letting a cat have kittens will not stop spraying and may worsen it due to hormonal changes.
Alternatives include hormonal medications and behavioral modification, but these are generally less effective. Always consult a veterinarian before making decisions about your cat's reproductive health.