Skip to content

usePrevious shouldn't use a ref #2162

Open
@barroudjo

Description

@barroudjo

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions