It is true that swimming near a pier heightens the risk of being bitten or attacked by a shark. They’re drawn by the same thing that the fishermen on the pier are, and bait in the water only adds to the effect.
However, you are correct that staying inside the breakers does not mean you’re safe. Check this out: