Here's my only 3 encounters and what I've done each time.
In Florida, at Sebastian Inlet, I had two encounters. Each time it was a smaller reef shark, I was told black tip, or white tip...can't remember which. Anyway, neither was huge, both in the 4-6' range. They zoomed in close to the surface, turned and swam right outside the lineup. Both times, I got out and took a break until they were gone (seemed to be gone). Locals, including my friend from Vero, just pulled up their feet and stayed in the water. They seemed unphased, I presume because it'snot all that uncommon. Both times the surf was really fun.
In NJ in September in the Mantoloking area, a much bigger shark was cruising just outside the lineup parallel with the beach. Some people were driving down the beach just ahead of it in a pickup honking and warning so surfers could get out. We all got out. Not sure of the type of shark, people were saying Thresher or Hammerhead, but it's dorsal and tail fin were out, and the distance between them was enough to make it scary. When it, and the truck leading it were a few hundred yards down the beach, me and two friends paddled back out. Most others either didn't go back out, or waited much longer. It felt sketchy, but it was 2'-4' offshore with these perfect little barrels. To have it without the crowd for a little while seemed worth it at the time
One of my friends couldn't surf for some reason, and caught the shark on video (not very exciting) but he also got some sweet footage of us. here's some frame grabs I took of myself just after the shark when we had it to ourselves. I'm thinking I made the right call :-)