☐ Why do heights give us sweaty palms and feet?

Why is it (in an evolutionary sense) that the palms of our hands and soles of our feet get sweaty when we are exposed to heights? This happens when we are actually in a position of being at altitude (e.g., on the edge of a roof, climbing a cliff, etc.), but also when we merely see photos or videos of others in such a position.

It makes no sense since having wet palms and feet makes it slippery and more likely to fall. This is a very counter-intuitive and backwards reaction. 🤨

Why would we evolve such a response?