The most stressful 30 days of your life, where you have find the new job, pass the interviews, negotiate for H1B, and make sure the new employer files the paperwork.
Doable, but extremely hard and you have to be lucky.
Legally that is a gray area. You are supposed to leave the country if you are unemployed. But USCIS usually ignores it if you file for a visa transfer in less than month from losing your job. (Alternative is that you have to leave US and get a new visa stamped and return)