I once met an Uber driver in San Jose who told me that he lost his job after his project was done in his consultancy. He was driving Uber till he gets a job and he is on H1B. It is illegal to do so but people have their own situations.
I'm still here without getting a H1B twice consecutively. 😅
No, it's not legal. If you do it anyway, you should still report it on your taxes. The IRS is not authorized to share your tax information with USCIS, and tax evasion is more serious than immigration violations.