They’re both expenses and they are both coming with different opportunities depending on the market, your life style and your personality.
From a market perspective, If the rents are high enough and potentially can pay the mortgage of 20 or 30 years, it makes sense to buy. If the rents are not high enough to cover a 20-30 years mortgage, then it makes sense to rent.
However it ends up being a lifestyle and personality decision. If you were investing that money that otherwise you would pay for the mortgage or/and other home related expenses, then it’s better to rent. But If you’re using your house as a savings account then it would be better for you to purchase.