The first ting I'd say is DON'T PAY THE RANSOM, there's no guarantee that you'll get the files back and by paying you will end up encouraging the people causing these infections to do it more. Some ransomwares are fake and don't actually encrypt your files so if you got hit with one of those you can recover them. However, nowadays, most of the time they will encrypt the files in a way that is impossible to recover from.
The best way to protect against the impact of ransomware is to keep regular backups and these backups should be stored offline (such as an external hard drive that is left unplugged), if you leave your backup drive plugged in, there's a chance that a ransomware infection would take out your backups as well!