reactjs / reactjs/react.dev

"Lazy initial state" is actually greedy

Open
#3,338 9 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Is there any good reason to call the useState(() => ...) feature "Lazy initial state"? The actual implementation is synchronous ("greedy") as far as I can tell, so I would propose to rename it to "Functional initial state" (for consistency with "Functional updates").

Related "Lazy initialization" in useReducer section => I would propose "Initialization function"

I can make a PR unless someone points out some aspect of the naming that I missed.

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 with the Hooks reference sections linked in the issue: “lazy initial state” and “lazy initialization.” Compare their terminology with the referenced ReactFiberHooks.new.js implementation and the “Functional updates” wording. Done means the documentation terminology is reviewed and any agreed naming is applied consistently in both sections.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, react
Domain
documentation
Issue type
Documentation
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.