Should we use "Functional" components + Hooks rather than "Class-Based" components?
Ali Bahaari
Posted on October 29, 2021
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 multiplecomponentDidMount
andcomponentWillUnmount
functionalities in your components and therefore this and other reasons which you may have faced cause much easier codes for comprehension.
💖 💪 🙅 🚩
Ali Bahaari
Posted on October 29, 2021
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.
Related
watercooler Why does a reboot make your PC run SO much faster than running all the cleaning tools you can possibly imagine?
November 30, 2024