DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’» is a community of 967,911 amazing developers

We're a place where coders share, stay up-to-date and grow their careers.

Create account Log in
Ali Bahaari
Ali Bahaari

Posted on

Should we use "Functional" components + Hooks rather than "Class-Based" components?

What does React say?

The FAQ of React docs site encourage us to adapt to functional components and hooks:

When you’re ready, we’d encourage you to start trying Hooks in new components you write.

Why?!

The only reason which never have described by even React docs in details is functional components are cleaner and much-easier-to-read ones. You can understand functionality of a component by glimpsing.

Consider you want to use componentDidMount and componentWillUnmount:

  • In class-based components these are separate methods which may need interactions with each other. Also they can't be redeclared in the component.
  • But by using useEffect hook, you can have multiple componentDidMount and componentWillUnmount functionalities in your components and therefore this and other reasons which you may have faced cause much easier codes for comprehension.

Top comments (0)

Update Your DEV Experience Level:

Settings

Go to your customization settings to nudge your home feed to show content more relevant to your developer experience level. πŸ›