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?
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
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?