Functional approach to React components (getting rid of `this`)
I don’t like this. I mean I don’t like this.
There are multiple articles on why OOP is not the best paradigm, and why it’s especially so in JavaScript.
One example is inheritance. Even Java folks know the Composition over Inheritance rule (thanks to J. Bloch?) and React team explicitly states this as well.
Another side of it is the infamous JavaScript this
, which is hard to deal with and which is known for making the code flow particularly tangled and messy.
But what really bothers me is how many new developers now who start straightaway with React skipping the basics of JavaScript (remember jQuery?) simply don’t understand the functional side of JavaScript. Cmon guys, the class is simply a syntactic sugar.
OK, enough grumbling for now.
I want to share a simple trick I’ve started using recently while developing one of my personal projects. It’s very simple. It abstracts away the...