Every whitewater kayaker, whitewater canoeist, and most rafters will end up swimming if they spend any kind of significant time paddling in whitewater. A paddler then has an important decision to make at this point. They must decide whether or not to stay with their boat and paddle or not. Ultimately, paddlers need to ensure they themselves are prepared for optimum whitewater safety.
Immediately after taking a breath try to see if any of your gear is within reach. This is not because you are trying to save your equipment, although that is a nice result. It is always better to stay with your kayak, canoe, or raft if you can since they will help you stay afloat in the whitewater. Staying with your kayak, canoe, or raft can also serve to protect you from smacking into any boulders as your boat should make contact first.
The correct way to float with your boat is to take hold of one of the grab loops. The person should hold this handle, lie on their back, and have their feet up and in front of them. The boat should be allowed to float downstream of the person. This way the kayak, canoe or raft will make contact with any obstacles before the person will. Furthermore, with the boat downstream of the paddler, the paddler is at less risk of getting pinned between the kayak, canoe, or raft and a rock, wall or strainer.
As the current and whitewater allows, the person should flip over onto their stomach and begin to kick while holding the boat, trying to get to shore. If entering more whitewater is inevitable, the paddler will need to flip back over on their back with their feet out in front to prevent them from going head first down the river.
The end goal is obviously to get to shore in one piece and with all of your gear. Of course, your kayak or canoe and paddle should be secondary concerns to your own safety. If you have the option to get to shore but it will require you to leave your boat or paddle, do it. You can always buy more equipment but you only have one life.