Agreed. Get a better offer and leave, never accept a counter offer intended to keep you.
Accepting a counter-offer in that situation is bad for several reasons. One is that the employer will be left with a sense of extortion and lack of loyalty from you. Another that you should realize that this employer was underpaying you and is either blissfully unaware of the market rates and thus incompetent or worse, malicious. In both cases you are better off working for someone who knows (or has HR who knows) and values your contributions properly.
If you accept the counter offer it should be for other reasons on your part such as that the current job has other benefits for you, such as physical proximity or CV boosting properties.
I've seen colleagues stay for years with golden handcuffs and it has never paid off. It leaves them with psychological misery and have made it much harder for them to get the next job.