For me my muscles in my feet and legs cramp when my electrolytes are low. So I add them. Many people use sports drinks.
I drink 150-250 ounces of water daily. That gives me my best hydration level and keeps my system clean. With some conditions your water intake is restricted for medical reasons.
When I have nighttime cramping in my feet, I add a bone supplement for 5 days. It has calcium, magnesium, zinc, and vitamin D. Then the nighttime cramps go away for 1-2 months.
I also walk 4-6 miles every day. I climb 1000-2000 stairs, I bicycle 90 minutes daily. So I am quite active.
Find what works for you. Baby steps.