First of all, make sure the frame your planning on getting will be a fit.
Then, as above work out what will fit & what you will have to replace. Do the sums to see how much the replacement bits will cost & decide if you can afford it/it's worth doing.
On the face of it, it's a good idea, rather than putting up with an ill fitting bike. You can always flog the bits that won't swap over to recoup some of the cost of new parts.
I bought an On One Inbred frame to transfer the bits from my old full sus to, when I replaced it with a new shiny one.
I bought new:
– seatpost (different dia. seat tube) ~£15
– front mech (old frame was e-type mount, not normal band fitment) ~£25
– saddle (not essential, but old one was knackered) ~£23
– bottom bracket (only as old one was knackered) ~£30
– shifters (not essential, but old ones were shagged) ~35
so only £40 of necessary new bits to get it going. Although you'll probably want new cables too.
Just make sure you have enough steerer tube length for the new frame. A new fork could get pricey….