I advocate embracing the web platform whenever you can. But vanilla JS doesn’t mean hand-writing every single line of code.
Sometimes, using a helper function or two is enough. Other times, a plugin. And sometimes, a full-fledged library or framework is the right call.
One question I get asked quite a bit is:
When should you use a framework? How do you know when it makes sense, and when vanilla JS is “enough.”
There’s some nuance here.
- If you’re building an app above a certain level of complexity, I personally think state-based UI makes things easier to manage and less prone to errors.
- If you’re using state-based UI that updates reactively to user interactions, you want to use DOM diffing instead of just re-rendering the whole UI with innerHTML.
- If you’re going to use DOM diffing, then it’s a good idea to reach for a framework because it’s really complicated and hard to do well.
If you’re going to use a library or framework, I recommend using a smaller one that forgoes a “virtual DOM.”
If you’re building apps with tons of data and DOM nodes (think Facebook, Twitter, Quickbooks), a full-sized framework like React or Vue may be a better choice.