{
  "id": 3829546,
  "title": "Understanding useMemo and useCallback",
  "url": "https://urgent.news/2026/08/27/understanding-usememo-and-usecallback",
  "topic": "tech",
  "section": "Tech",
  "published": "2026-08-27T18:37:56.000Z",
  "source": {
    "name": "Lobsters",
    "slug": "lobsters",
    "url": "https://www.joshwcomeau.com/react/usememo-and-usecallback/"
  },
  "original_language": "en",
  "account": "Understanding useMemo and useCallback can seem daunting at first, but they are essential hooks in React for optimizing performance. useMemo allows us to \"remember\" a computed value between renders, which can prevent unnecessary calculations and improve application performance.\n\nImagine a scenario where an application needs to compute a list of prime numbers based on a user-specified number. If the user selects a large number, the application will need to perform numerous computations, which can be time-consuming. This can lead to performance issues, especially if the user performs other actions while waiting for the results.\n\nMemoization, which is what useMemo does, is a technique used to cache the results of expensive function calls and return the cached result when the same inputs occur again. In our example, useMemo can be used to cache the list of prime numbers. The dependencies passed to useMemo act as an invalidation strategy. If the dependencies (like selectedNum) change, useMemo will recalculate the primes; otherwise, it will reuse the previously calculated value.\n\nThis can be particularly useful in scenarios where the same expensive function is called multiple times with the same arguments. However, it's not always the best solution. Sometimes, restructuring the application to push state down rather than lifting it up can avoid the need for useMemo. This involves breaking down the application into smaller components, each managing their own state.\n\nIn the provided example, the App component was managing both the selectedNum and time states, leading to unnecessary re-calculations. By separating these states into their own components, Clock and PrimeCalculator, we can avoid this issue. This approach promotes a more modular and maintainable codebase, even if it's not always the optimal solution.",
  "summary": null,
  "key_points": [],
  "editors_take": null,
  "illustration": null,
  "coverage": {
    "outlets": 1,
    "also_reported_by": []
  },
  "ai_generated": true,
  "disclaimer": "Summaries, key points and the editor’s take are written by software from other outlets’ reporting and may contain errors — always check the linked original."
}