React developers intrigue us with the so-called React Forget compiler [that’s supposed to inject useMemo and useCallback into code automatically]. However, we still can't figure out best practices for useCallback, useMemo, and React.memo when we write it on our own. The worst scenario is if we continue to put it everywhere without understanding. As a result, it can bring noticeable harm to the performance of our application. In this talk, on real-life use cases, you will see solutions to the problem of using hooks wrong or overusing them!
Don't Forget React Memo
AI Generated Video Summary
The Talk covers topics such as React memo compiler, use memo and use callback, building custom hooks, and the benefits of using use ref. It also explores the similarities between use memo and use ref, and the use of React Memo for preventing re-renders and optimizing expensive calculations. The speaker also shares personal information and contact details.
1. Introduction to React Memo and Custom Hooks
I'm going to talk about the React memo compiler, the gap in understanding how use memo and use callback works, and the best practices. I will also discuss building a custom hook and the benefits of using use ref instead of use state. Finally, I will introduce my own use memo function with shallow compare.
Okay, hi, everyone. I'm so glad that you have joined me and make some little bit noise. Let's make some interactions. Where is the noise? Yeah. So, have you ever – okay. Have you already seen React Conf 2021? Please raise your hands up. Oh, so few. Okay. Just a quick look through. It has a new compiler called React memo, which is supposed to inject React memo, use callback, use memo, automatically in your code. It sounds really fascinating, but unfortunately, it's still a developer mode and I have no clue when it's going to be in the nearest future.
So, let's back up to our daily life, and I notice that there is still a gap of understanding how use memo and use callback works. We are overusing it. About what is that memorization? And the hardest question is now how can we figure it out the best practices? So, let me introduce myself. My name is Kristina. I'm software engineer at SoftSurf. And today I'm going to talk about it in details.
2. Exploring use Memo, use Callback, and React Memo
I discuss the similarities between use memo and use ref, and the extra condition check in use memo. I also share my knowledge on using use callback and use memo, such as wrapping child components with React Memo to prevent re-renders and creating Howk components with dependencies. Additionally, I mention the use of use memo for optimizing expensive calculations like filtering and sorting. Lastly, I dedicate a slide to my country and provide information on how to find me on Google, Twitter, and Github.
Then I evoke shallow equals where I started checking for is it array for its length and finally I check it for their items are new for us. If everything is okay it returns true and then we override it and return a value so making like shorting something up we can modify object not only by use ref. How was interesting for me that use memo is so similar to use ref but the only difference is that it has extra condition check and there is another question comes to me that if use call back is equivalent to use memo and now it's not a secret and we can understand why.
And now I just want to take a bonus part of it and to share my knowledge how I use use callback and use memo. First one when you have parent component and child component. If in parent component you use use callback I highly recommend you to wrap child component with React Memo to prevent its re-renders. And next one is when you want to create your own Howk component with dependencies. I also recommend you to wrap it with use callback. If you don't do this, don't worry! Yes, Howk plugin will call you back. And another example of using use memo. It's quite simple for optimizing expensive calculations such as filtering, sorting, and fomenting. And the great example is React table does.
And the last slide is dedicated to my country. We still need a support. We still need some donates and ammunition. Here you can find further information and don't be afraid to ask Ukrainian any questions you have. And here, if you want to find me in Google, in Google, you just can write my nickname and you will follow to my Twitter and Github. I will be really appreciative of you if you join me.