For example, for useRef, it's constant order. For useCallback, it depends on the number of dependencies. And useState depends on the number of updates. So, if you have something that updates the state a thousand times between renders, that's going to be a hit on CPU, but probably nobody's doing that. Then there's memory. You have to store the hook object, you have to store the queues, the effects, you have to store the memoized state, you have to store the dependencies. Those can be many things to store the dependencies. But, well, let's see what a practical example. For example, we have a useMemo, or just passing the style like that. So, the option on the right, in theory, is better, because that way we don't have to check the height on every render. So, that's less CPU. And we don't have to store the dependency list with the height, we don't have to store the height object, the style object on the hook for returning it every single time. So, the one on the right is better, right? Well, if you look deeper, the props are still stored in the fiber, because you need them to compare the current fiber with the previous one to see if anything has changed. Also, the way style works is interesting on the inside. On the left side, you have what the DOM does, and on the right side, what React Native does.
Now, at the end of the day, when you are passing styles, it will check every single style to see if there's a difference in order to decide what style to change. So, yeah, probably that is going to take a few more loops than just using a useMemo. But, well, that's all that I wanted to share today. What did I miss? Lots of details. Also, reconciliation, class components, suspense, context, server-rendering hydration, many hooks, children reconciliation and key handling. I missed a lot of things, but, well, it's 20 minutes, and that's what we can fit here. But, yeah, there's still a lot of details to look into. But, well, we can look at that in the future.
Okay. That's everything for today. Thank you very much. Have a great day. ♪♪♪
Comments