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

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

Open
remorses opened this issue Jan 2, 2025 · 0 comments
Open

Comments

@remorses
Copy link

remorses commented Jan 2, 2025

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.

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

No branches or pull requests

1 participant