sbookvova.blogg.se

React use memo
React use memo







react use memo

If you have a pure function that the idea of a pure function is like.

react use memo

If all these other things that you rely on are the same, don't run. It's saying like, hey, generate random number, that was an expensive function, right. It's like use effect and use callback are hanging out with each other. You've probably heard of these before, useMemo is a way to say use effects friend. UseMemo not to be confused with react now and useCallback, right. But generally speaking react has some tools to help us with this. Where I was just opting out of most of the goodness anyway. Unless you do the kind of class components I was writing before I switched over to functional components. Unless you do some of the modern stuff, where you're gonna assign it to a class variable. So, point four class-based components, that methods are the same object in memory every time, you're not redefining them. They're the same function attached to that object on the prototype, right. Interestingly, this is not as much of an issue with classes, because methods are the same. And react has those tools for us because this is obviously like, why would react memo exist if you use hooks and thereby? It wasn't a thing. So we clearly need like a few more tools in order to handle this, right.

REACT USE MEMO CODE

It's like the code works just not as you expected, but it works. Okay, the rules of react, memo apply, everything works, right.

react use memo

So it compares this function to another function, different memory addresses. > So like these are different values are stored. Transcript from the "useMemo & useCallback" Lesson









React use memo