react.dev icon indicating copy to clipboard operation
react.dev copied to clipboard

[Typo]: explanation of useMemo first-render return value, doesn't make logical sense

Open alin-sofianu opened this issue 7 months ago • 2 comments
trafficstars

Summary

Inconsistent explaining on what useMemo returns on first render.

Page

https://react.dev/reference/react/useMemo#reference

Details

From article, in order:

On the initial render, useMemo returns the result of calling calculateValue with no arguments.

On the initial render, the value you’ll get from useMemo will be the result of calling your calculation.

The first sentence, to me does not make sense, as calculateValue is called with arguments, it's just that dependencies don't factor in yet on first render. Or my bad sorry:)

alin-sofianu avatar Apr 20 '25 15:04 alin-sofianu

please assign me this issue @alin-sofianu

tusharagrawall avatar Apr 27 '25 10:04 tusharagrawall

Thanks for the feedback. I'm trying to figure out if we could clarify this to avoid confusion without causing other issues.

The first sentence, to me does not make sense, as calculateValue is called with arguments, it's just that dependencies don't factor in yet on first render.

Can you explain more about how you understood useMemo to work?

This is a common point of confusion, so let me clarify so we're on the same page. The callback passed to useMemo is never passed any arguments: not on initial render, and not when the dependencies change. That's why in all our examples, you'll note that there are no arguments listed, it's always () => .... Notably, sometimes people assume that the dependencies array will be passed as an argument, but that is not the case.

I'm curious to hear how you thought it would work, because that would help us understand how to adjust the text to ensure that it's clear for more people. Thanks!

josephsavona avatar Apr 29 '25 06:04 josephsavona