The key in surf is to never fight against the rip. While it can feel scary to get pulled out, remember that 99% of the time, it will end after you are pulled past the break, at which point you can swim laterally a bit and then go back in with help from the waves. Breaking waves naturally create alternating channels in the sand that either push you towards the shore or pull you back out to the break.
The other 1% of the time is when you are close to the mouth of a bay or some other feature that creates a current independent of the dynamics in the surf zone. You'll know that's the case if the current stays strong after you're past the break. If it's too strong for you to swim against it, then you're in trouble and should start waving for help.