No, it’s is NOT better to replace an AP class with an easier class when you are getting a B in that AP class.
Grades are generally more important than ECs. Depending on the EC, maybe you need to carve out a little more time to devote to your AP class. If your ECs keep you sane, then figure out a way to create a little more time somewhere else. For instance, maybe less screen time, or take a shower instead of a bubble bath.
I’m guessing you just need to find an extra hour a week and you could much improve the grade. Go see the teacher for extra help if it’s the content that’s causing you trouble.