And then React came along and brought us a totally different landscape where everything was inside JavaScript, which was very nice at the moment and made a lot of sense, but still, there were some parts of this new paradigm that didn't sit well with me at all. So in the beginning, we have classes, and it was a bit convoluted, a bit complicated, as you can see, you know, to declare a simple app, you have to go for all those states. And a bit verbose, a bit counterintuitive since I personally was more into a functional style approach, having to do with classes was good, but not ideal. But then later in time, React adopted hooks, which for me, made everything click, made a lot of sense, we have a more well-defined API to control state, and it was more explicit, it was more simple to understand and create apps.
So for the first time ever, I felt that I have what it takes to create very amazing experiences like the one that I'm showing to you. For me, React was the solution that I was looking for to create my web apps in a performant way, in an easy way that I could declaratively create the interfaces that I was trying to do at the time. But if you're like me, you also run into this problem that you create your first app, you're very excited, and then you go to the dev tools, you turn on the updates, highlights, and what do you see? Your whole React app becomes basically a Christmas tree, where everywhere in your app, it's updating all the time with every effect with every change.
So to understand why this happens, first, we need to understand how React was imagined at first, and how it became to be. Basically, the way that React handles the updates in our components is we have the parent component, and every time there is an update there, you click a button, you submit the form. What happens is all the children also get an update. Basically, if you click, let's say you submit a form, and you have a lot of children, because the parents change, all the children have to change to make sure that you propagate the change across all your apps. Which makes us think that React can be some overreactive at times, which it was fine, but as you grow your application, as you try to create more complex things, you're definitely going to see that we need more tools to make our applications faster and to make sure that we update in state only when we have to. So what are the current options that we have right now for this specific case? Basically, we can look at our app here, where we have a very simple e-commerce app, and you can see here that I create this demo code, by the way, just to highlight a simple case where we could apply some optimizations with the current APIs that we have available to us right now at the moment.
Comments