You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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.
The text was updated successfully, but these errors were encountered: