![]() When appropriate, you can use it to improve performance. Now I'll briefly explain how mo works (but we'll also discuss it later in the article). In a simplified example: "string" = "string" // true Non-primitive values refer to the same object in memory.Primitive values are equal (check the link above for the few exceptions). ![]() You can find the detailed explanation of Object.is here but in short: When React compares the values used in a dependency array such as useEffect, useCallback, or props passed to a child component, it uses Object.is(). No big deal, the example project is just a summary of the main points you will learn now.īefore we start comparing these two hooks, let's review some necessary background concepts. Official Beta Documentation for useCallback and useMemoĪs always, I've provided a sample project so that you can test in a simplified environment everything that is explained here.Still, it's important to know these tools and know when to use them if you see the opportunity. Before you apply these utilities, your own code will offer you more opportunities for improvement than most of the performance gain you'll get by using what you will learn here. In this article you will learn the differences between useCallback and useMemo as well as how to measure the gain of the improvements you're getting in the codebase.īefore we begin, you should note that the following methods for optimising React are really last resort options. There are some hooks available to help with this, but you might not be sure about which one to use and when. We all want to build powerful applications and avoid unnecessary renders.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |