Magnesium hydroxide is insoluble,and hence,it does not allow the pH of thre stomach to go above neutral.
However sodium hydrogencarbonate (NaHCO3) is solube, and and an excess of it can make the stomach alkaline and trigger the production of even more acid,
So,magnesium hydroxide is better antacid than sodium hydrogen carbonate
Additional information
An antacid is a substance that neutralises stomach acidity and is used to relieve heartburn, indigestion or an upset stomach.