reactjs / reactjs/react.dev

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

Open
#7,402 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

type: documentation
Dominant language
JavaScript
Stars
11.8k
Forks
7.9k
Avg merge
1d 11h
Merged PRs (30d)
11

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the linked React useRef reference page and review the explanations of render purity and ref initialization. Change the relevant wording from “pure” to “idempotent,” then verify that the page accurately describes the requirement for interrupted and repeated renders.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, react
Domain
documentation
Issue type
Documentation
Difficulty
1/5
Estimated time
Under an hour
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.