react.dev
react.dev copied to clipboard
[Suggestion]: Make clear why Ref was used in the third solution
Summary
The solution for the third challenge, "Fix debouncing," does not require a Ref. Moving the let timeoutID; to the top inside the DebouncedButton component will fix the debouncing. Either point this out in the explanation or make it re-render so the solution requires Ref.
Page
https://react.dev/learn/referencing-values-with-refs
Details
Since code example does not use State, there's no re-rendering, and so there's no need to use Ref to remember anything across re-renders. The page mentions that Refs are not used often; although future-proof, I think the example should only use Ref when necessary.