I think you need a bit of both. Hobby projects are a great way to solidify specific learnings. You want to learn CSS? Build a website! Simple, right? But we tend to build our hobbies differently, we treat them specially, and it's easy to get bored when they're no longer about the thing you wanted to learn about.
Building stuff for other people forces you to bend the project in ways you might not want to. It forces you to focus on their problems rather than your own. It also forces you to actually deliver. I've got countless projects that went nowhere once I was satisfied I'd learnt the initial, easy, 80% of the area. It's that remaining 20% that makes you an expert, though.