Make it clearer how to run an effect only once (componentDidMount style)
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 11.8k
- Forks
- 7.9k
- Avg merge
- 1d 11h
- Merged PRs (30d)
- 11
Description
Based on this conversation on Twitter, it's perhaps not clear enough how to make an effect hook only run once on mount (a la componentDidMount.)
The relevant info on how to do it properly is tucked away near the bottom of the effect hook doc, in a footnote of this tip. This is a major use case that should probably have higher priority in the documentation. I imagine a vast majority of apps actually need to do use an effect in this manner.
I assume people are probably doing something like
function MyComponent({ fetchData, data }) {
useEffect(() => {
if (!data) {
fetchData()
}
})
}
I can make the change to the docs, but where's the best place to put it? Should I make it a tip? Does it deserve higher priority than that?
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
Start with the effect hook documentation and its “Tip: Optimizing Performance by Skipping Effects” section, where the once-on-mount guidance is currently tucked away. Decide whether the useEffect-on-mount example belongs in a higher-priority section or tip, then confirm the documentation clearly explains the intended pattern.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, react
- Domain
- documentation
- Issue type
- Documentation
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100