No, Yanfei would be a terrible idea if you have both her and Razor.
The reason is that Razor is a pure main DPS. He is useless off the field. He must be on the field to be worth anything. Yanfei, likewise, is also a pure main dps. You can’t have both on the field simultaneously, so you’re just wasting a slot.
However, Yanfei is still a good addition if you’re building a second team. For spiral, you do need two separate teams, so it is still good to get a Yanfei. But she won’t go on that team that has Razor. She’ll go on a separate team.
A good thing about investing in Yanfei is that she uses either Crimson Witch or Lavawalker. You can always transition her artifacts if you ever get a better Fire DPS. And there are a lot of them. Diluc, Hutao, Yoimiya, Klee, and even Xiangling (if you do the National Team setup). So it’s not like you’re wasting anything if you build her.
Switching out Razor for Beidou is a big change, however. Razor is a character that requires a lot of time and investment to build well. He’s a 4-set Gladiator user after all. Beidou, meanwhile, uses the Thundering Fury set. Do you really wish to throw everything away?
(Exception: if you’re building for Spiral Abyss and need the options. But you shouldn’t be worrying about such things until you’ve cleared floor 12 at least once)
Not that there’s anything wrong with the switch. But understand that you’re looking at a major revamp of your Genshin investment if you do so.
Yanfei is an amazing investment if you’re planning on building a second team. If you’re thinking about putting her in your first team, you’re going to need to replace Razor with her, which is a major revamp. It’s not an incorrect choice, but it does have rather heavy consequences, especially if you’re still in early/mid game.