This seems like a fairly organized, but still jQuery-like approach without the cross-browser safety of jQuery. You're still doing manual DOM querying and state manipulating instead of something more declarative.
Gzipped and minified, Vue is just 20kb. It's so light weight that there's almost no reason not to use it for adding ad-hoc rich interactivity on a given page.
Preact is fabulous. I've used it a few times for simple sites. Now it even has Hooks, a CLI, and still loads in 120ms on a 2G network. And if shit gets really complicated, you can convert to a React app and keep all your code. It's quite nice.
Also React is not a framework, it' a library. People who go into React thinking it's gonna organize their code for them are gonna have a bad time.
As I understand it, React normalizes the event system so it is consistent and all events work the same across all supported browsers (for example, certain browser events will not bubble, but React’s will). This synthetic event system, type checking, and now, their systems related to asynchronous rendering take up the bulk of the size of the library. If you only need simple click handlers, you don’t need these things. If you need to deal with very complex event handling, React can be helpful.
You pretty much loose the eco system and all the bits and pieces that advance React, async rendering, cross platform and reconciling, fiber, suspense, etc. Some of these are ground breaking. Like dwighthouse said, React also normalized events, but this is not such a big deal any longer as pre evergreen browsers are dead, React will shed normalized events soon.
How does it go in terms of dropping it onto a page with limited build tools? My use case would be something simple like displaying cards based on an ajax request, along with dropdowns/selects for tags/categories and pagination.
I've only learned React's basics, so for most of my projects which aren't large webapps I've been turned off from webpack's build process. Typically use gulp for all my stuff, how'd it go in a situation like this? Sounds appealing so far.
Edit: I'm usually building in PHP (WordPress) hence dropping onto a single page or two where's there's actual functionality to build. The stuff I've done using jQuery got messy quite quickly, even with using a fake state to store data before writing to the DOM
I use Preact without build tools. (P)react is fully capable of running in a browser by itself with vanilla JS code. To use JSX, though, you need a transpiler, fall back to Hyperscript, or use something like htm.
Embed a <script> tag pointing to ./node_modules/preact/dist/preact.umd.js in my app (I use UMD). Now, I can access preact as a global variable.
Alternatively, use ./node_modules/preact/dist/preact.module.js if you prefer ES6 import.
If you want, preact/compat and preact/hooks are available as separate JS files in ./node_modules/preact/compat/dist/ and ./node_modules/preact/hooks/dist/.
I started using Preact just yesterday for a small project and I'm amazed how good it is. So far I haven't hit any "oh come on, but react has it!" (I use v10 for hooks). And it's only 3.6k. Perfect for small projects
80
u/phpdevster Sep 23 '19
This seems like a fairly organized, but still jQuery-like approach without the cross-browser safety of jQuery. You're still doing manual DOM querying and state manipulating instead of something more declarative.
Gzipped and minified, Vue is just 20kb. It's so light weight that there's almost no reason not to use it for adding ad-hoc rich interactivity on a given page.