Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

usePrevious shouldn't use a ref #2162

Open
barroudjo opened this issue Apr 17, 2023 · 2 comments
Open

usePrevious shouldn't use a ref #2162

barroudjo opened this issue Apr 17, 2023 · 2 comments
Labels

Comments

@barroudjo
Copy link

Ref shouldn't be used when reading or writing for a value used when rendering: https://react.dev/reference/react/useRef. And the output from this hook can clearly be used for rendering.
The react doc actually explains how to do this, and it is a bit dirty: https://react.dev/reference/react/useState#storing-information-from-previous-renders.

Here's the issue that I opened, to which Dan Abramov answered and made me aware of this problem: facebook/react#25893

@hchlq
Copy link
Collaborator

hchlq commented Apr 21, 2023

Thank you for your suggestion. In future major versions, we will consider removing it and using a better solution.

@hchlq hchlq added the v4 label Apr 21, 2023
@Simon-He95
Copy link
Contributor

It may be possible to store a pre through a closure to replace the use of Ref, but there will be a big change in use from the previous

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants