Understanding useMemo and useCallback
If you've struggled to make sense of useMemo and useCallback, you're not alone! I've spoken with so many React devs who have been scratching their heads about these two hooks. My goal in this blog post is to clear up all of this confusion. We'll learn what they do, why they're useful, and how to get the most out of them. Let's go! This tutorial is written to help beginner/intermediate React developers get more comfortable with React. If you're taking your very first steps with React, you might wish to bookmark this one and come back to it in a few weeks! Alright, so let's start with useMemo. The fundamental idea with useMemo is that it allows us to “remember” a computed value between renders. This definition requires some unpacking. In fact, it requires a pretty sophisticated mental model of how React works! So let's address that first. The main thing that React does is keep our UI in sync with our application state. The tool that it uses to do this is called a “re-render”. Each re-ren
Introduction If you've struggled to make sense of useMemo and useCallback , you're not alone! I've spoken with so many React devs who have been scratching their heads about these two hooks. My goal in this blog post is to clear up all of this confusion. We'll learn what they do, why they're useful, and how to get the most out of them. Let's go! Intended audience This tutorial is written to help beginner/intermediate React developers get more comfortable with React. If you're taking your very first steps with React, you might wish to bookmark this one and come back to it in a few weeks! The Rea
saved by
related reading
- What is Memoization? How and When to Memoize in JavaScript and Reactfreecodecamp.org
- useMemo – Reactreact.dev
- You Might Not Need an Effect – Reactreact.dev
- useCallback – Reactreact.dev
- Blogged Answers: A (Mostly) Complete Guide to React Rendering Behavior · Mark's Dev Blogblog.isquaredsoftware.com
- Why React Re-Renders • Josh W. Comeaujoshwcomeau.com
- How to write performant React code: rules, patterns, do's and don'ts | Developer Waydeveloperway.com
- React re-renders guide: everything, all at once | Developer Waydeveloperway.com
- Pure components in React: Using PureComponent and React.memo - LogRocket Blogblog.logrocket.com
- Implementing React from scratchrob.directory
- When does React re-render components? | Felix Gerschaufelixgerschau.com
- SWR: React Hooks for Data Fetching - Vercelswr.vercel.app