flâneur — a map of the web's best reading

Understanding useMemo and useCallback

joshwcomeau.com · 5,804 words · saved by 2 readers

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

Explore this link on the map →

saved by

related reading