How I converted my React app to VanillaJS
hackernoon.com
hackernoon.com
We often take our tools for granted, without thinking about how they were designed. Doing such exercice allows both to get insights into the possible solutions for a problem one of our tools solves (allowing us to understand our tools better), and also is proper training for architecturing our own tools.
Thanks for sharing your discoveries.
A fun read as well.
const h1 = () => makeElement(`h1`); makeElement(`h1`)
everywhereafter this declaration you can write
h1()
insteadjust a shortcut function
const h1 = () =>
Is this new syntax declaring a function named h1 that returns a function or what? I don't understand what the empty pair of parentheses means. const h1 = function() {
return makeElement('h1');
}
Arrow functions without arguments need empty paranthesis.They also have an implicit return if you don't use {}
So it's not just a syntactic shorthand but there's also a semantic difference.
var h1 = function() {
return makeElement(`h1`);
}
Edited to reflect the valid point brought up in the commentsAlso, no "arguments" (there are ...rest parameters that allow for variadic functions).
I thought the arrows were now binding to surrounding context? (e.g. https://babeljs.io/blog/2015/06/07/react-on-es6-plus)
It's a little old now, but still worth a read.
Great work.
Its not a bad thing when 95% of the code in your project is borrowed (i.e. when you use a framework), but ducktaping stuff together will only get you so far.
For the size of the example project (single dev, one day, single page) and the requirements (load as fast as possible) this would be the superior approach. React would indeed be overkill. And below 200ms load times has proven impact on conversions. That is: the requirement is realistic and commercially, if at all possible, not at all negotiable.