That's situation-dependent: there's often stuff a company can do if you're highly cash-motivated (promotions, other title changes, bonuses, …) to retain you.
On the other hand, often there's not! Especially in older / larger orgs or ones with unconventionally rigid payscales. Even in that situation, I'd generally stand by the recommendation: there's a chance they will find a way to accommodate your needs, and if not you have cemented a strong relationship with your manager and above that will benefit you way into the future.
A few other commenters have mentioned the benefits they have realised by leaving gracefully. IMO this expected upside outweighs the short-term risk, at least in the sorts of roles the post is (now) aimed at.