Skip to content

[Suggestion]: render function should be idempotent, not strictly pure #7402

@remorses

Description

@remorses

Summary

React docs explain in many instances that render should be pure and you should not read or update refs for this reason, because some features like Suspense can interrupt rendering and restart it.

But from my understanding render can be impure, what matters is that render must be idempotent, meaning interrupting render and calling it again with the same props will always return the same result. The exception given in the docs (using a ref for initialization) works because it is idempotent.

There are many other idempotent but not pure use cases, for example the implementation of what was called useEvent makes use of refs during render but should be fine.

Page

https://react.dev/reference/react/useRef#referencing-a-value-with-a-ref

Details

Change wording of pure to idempotent.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions