Aren't updater functions in state an antipattern?
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 11.8k
- Forks
- 7.9k
- Avg merge
- 1d 11h
- Merged PRs (30d)
- 11
Description
In documentation here:
https://reactjs.org/docs/context.html#updating-context-from-a-nested-component
An updater function is placed directly in the state object for the sole purpose of passing it down through context:
this.state = {
theme: themes.light,
toggleTheme: this.toggleTheme,
};
This seems like an odd antipattern. I've never placed a method in state before. Shouldn't state be exclusively for properties that affect rendering and change over time?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Review the linked React Context documentation, especially the “Updating Context from a Nested Component” section and its updater-in-state example. Determine whether the example needs clarification or revision, and consider the work complete when the documentation gives a clear, agreed explanation of this pattern.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, react
- Domain
- documentation
- Issue type
- Documentation
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100