DEV Community

Discussion on: React: Class Component VS Function Component with Hooks

Collapse
 
curlywurlycraig profile image
Craig Wilkinson • Edited

The useEffect call in your example is missing an empty dependency list. This probably isn't quite doing what you think: it's setting up a new timeout every time the component re-renders.

Ironically, a class component almost certainly wouldn't have such a problem because of the clearly named componentWillMount method.

That said, helpful article and I am generally a fan of function components.