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

[Suggestion]: Make better use of ref in the last challenge of the docs

Open Spoof14 opened this issue 1 year ago • 2 comments

Summary

Remove useless useState and simply use ref

Page

No response

Details

The docs in the 4th challenge suggest using both a useState and a ref for managing the value of a component when there is a delay. This is unnecesarry and we can simply use the ref. https://react.dev/learn/referencing-values-with-refs#challenges

Spoof14 avatar Oct 20 '24 21:10 Spoof14

#5485 https://github.com/reactjs/react.dev/pull/5485/files

Spoof14 avatar Oct 20 '24 21:10 Spoof14

As someone who is following the Learn React docs in order, I don't think this change is necessary. The current explanation draws a helpful distinction between the appropriate times to use State and Ref. Moreover, the proposed concept has not been introduced up to that point, so it will be confusing to readers. According to the contribution guideline:

Learn React is designed to introduce fundamental concepts in a step-by-step way. Each individual article in Learn React builds on the knowledge from the previous ones, so make sure not to add any "cyclical dependencies" between them. It is important that the reader can start with the first article and work their way to the last Learn React article without ever having to "look ahead" for a definition.

liy-che avatar Mar 27 '25 20:03 liy-che