Why and what I love about React.js

Yevgeniy Ivanov
3 min readJun 8, 2021

When it comes to single-page application development, there are more options than one could probably memorize. In general, react.js is ranked near or at the top. The Facebook team accomplished something great with their development of the framework. In a sense, it was a no-brainer for a website with a massive potential amount of components being displayed to focus on… the component, and how they interact and share data. Not to mention that being “DRY” and adhering to the “single source of truth” idea has saved many a developer hours of their lifetime and many a keyboard its keys in the never-ending journey of debugging. If I tried to liken this framework to a board game, it would be a strange hybrid of dominoes and puzzle pieces. Dominoes due to the cascading, hierarchical nature of states and props. Changing state up the chain of prop hierarchy has the ability to re-render or modify every component beneath it. And puzzle pieces because many different components come together to make one coherent whole that the user experiences.

Javascript thinks callbacks are so nice, it decided to use them… Everywhere. Maybe one day soon the processing power available will be enough to cast every operation synchronously with no detriment to the user experience. While that’s still not the case, asynchronous javascript and callback functions take pity on our delicate attention spans and in tendem, make sure our experience of the web is smooth, prioratizing performance over glamour. It would be unberable to load all the relevant data and display all the assets synchronously. Which is why, while Javascript ran on browsers is single-threaded, it can seemingly perform multi-threaded operations with its Web API stack features. The tasks are handled in the background by these API’s and what’s returned is a nice, fresh out of the oven objects ready to hit the stack. Now, thunk is a function that is returned from another function. In what possible scenario might that be useful? Well, this is where the idea of callbacks becomes crucial.

In the process of baking a pie, the worst thing the average person will do is add a little too much of something, or maybe missread and miss a step. When it comes to the way a processor would communicate, however, the instructions not only need to be step by step and accurate, but the order matters. And some things take longer than others. Just like in our pie, you wouldn’t want to take it out of the oven while the dough is still not ready just to move onto the fillings.(Don’t quote me on pie making, I’m still at the ramen stage) What a thunk essentially does is let the code execute a function on cue. In the case of the react thunk middleware, an object is also passed into the thunk with a little help of our friendly closures. So in essense, react thunk’s role in our soon to be pie is to be able to pass say that once the pie is properly cooked, can set set an action(dispatch) that can then impact our state. For example, once we take the pie out, we can dispatch an action that changes our project from being incomplete to being ready and delicious. And once the appropriate guests(components) are made aware that the pie in nice and ready, they can alter what they do and display in response(in React-ion).

--

--