There are many different hecklers. Some are just chatting with you. That can be an annoyance, but is pretty minor. Some just need something to do. Really, if you are not engaging everyone in the crowd, then some will find something to do, and it may not be what you want them to do. You engage the crowd by talking to everyone in the crowd. Even if you are focusing on one person, you can direct some of your asides and throw away lines to various other people in the crowd. Always look them in the eye.
Then there are the jerks. These are rare, or should be rare. If you are a kid, then you will get a lot of them from people at school, at least for a while. It will become less frequent with time.
You have to handle the jerks, but you can't seem like one of them. This is hard and can take years of experience. Sometimes just ignoring them will work, sometimes not. There are some books where you can learn somethings to do--and not do. But never look flustered--never look nervous. This takes tremendous body language control.
One thing you can try if you have a really bad heckler is to simply stop and announce, that "In all the years of performing, I have never met someone so interested in talking as this person here (the heckler.) Therefore, I am going to let them talk while I watch" [You then walk into the audience, near the heckler and then say,] "You sir, please walk to the front of the audience and say everything you want to say--anything at all--while I wait here in the crowd. When you are done, I will finish the trick."
This works OK on the street.
Lets say you have a heckler to your right who won't shut up. If you happen to have a large person to your left, you can turn to the guy on the left and say as an aside (but loud enough for all to hear) "Hey, he just called you Edited (or fat, stupid, etc.)" If the heckler continues, then back away from the big guy on the left and say, " Hey, I am staying out of this." With some humor this can work too. But it has to cause the person on the left to laugh. Do not do this if the heckler is belligerent at all or if they are bigger or tougher looking than the person on the left. Do this only if the person on the left and the heckler see it as a joke. This will only work if the heckler is just persistently annoying, not if they are being aggressive.
But you better be very calm and in control and show some humor.
I have actually done both of these once. They both worked. The hecklers in both cases were jerks, but not really serious jerks, so they shut up pretty fast, in fact they laughed when I was done. I did not think up either of these, I think they both come from Gazzo. Keep in mind, though; some hecklers won't lose no matter how good you are unless you can get the audience to help. That may or may not happen when you want it to.