From the course: Build Modern Web Apps with React, Hooks, State Management, and APIs Using Vite or Next.js

Unlock this course with a free trial

Join today to access over 25,200 courses taught by industry experts.

Functional vs class component

Functional vs class component

Hi, let's see in the functional versus class what we know so far and what we should keep in mind in the future. Functional components are preferred in modern apps. That means they are the future. It has a simpler syntax. Hooks make them very powerful and we can have logic reuse as well. It's not that a specific hook can only be used in one functional component. You can even create hook of your own and you can use that logic in multiple function components too. Just like the useState, useEffect and other hooks. We can create multiple functional components and we can use these hooks anywhere up to our choice, whereas the class-based components are required only in the legacy codebases. You need to have an understanding of class-based components if you are working on a legacy codebase. Now, let's see an example that why function components are preferred. Let's move back to base code, over here we have the counter functional component as well as the counter class component. If I make an…

Contents