Can h4 dependent visa holder live in different city in us

If H1 visa holder stay in State A in USA and H4 Visa Holder stay in State B due to some personal reason , is it legal to stay in different state?

This should be okay as far as the primary H1B and dependent H4 still remain related either as dependent spouse.

Thanks for the response …