Hi guys,
In this lesson, we will talk about the differences between functional and class components in React.
In React, we can write our components in two ways. One of them is functional and the other one is the class component.
Functional component is the simplest way to write the Component in react is to write a JavaScript function.
Class Components uses the ES6 class structure to write components.
Both of them can be used to write a component in React. They are alternative ways for each other.
A functional component is just a plain JavaScript function which accepts props as an argument and returns a React element.
A class component requires you to extend from React.Component and create a render function which returns a React element.
a functional component is just a plain JavaScript function, we cannot use states in our component. That’s the reason why they also get called functional stateless components. So everytime you see a functional component you can be sure that this particular component doesn’t have its own state.
Another feature which you cannot use in functional components are lifecycle hooks. The reason is the same like for state, all lifecycle hooks are coming from the React.Component which you extend from in class components.
On the other hand, with functional components, we can end up with less code when we compare it with class-components.
Also, Functional components are much easier to read and test because they are plain JavaScript functions without state or lifecycle-hooks.
In the next lessons, we will see the details of them with example cases. If we write a code with class-component, we will convert it to function-component or if we write a component with function-component, we will convert it to class-component and we will see the different implementations of both of them. And we will figure them out.
That’s all for the beginning.
Thank you.
Смотрите видео Functional Component vs Class Component In React | React Hooks онлайн без регистрации, длительностью часов минут секунд в хорошем качестве. Это видео добавил пользователь Senol Atac 01 Январь 1970, не забудьте поделиться им ссылкой с друзьями и знакомыми, на нашем сайте его посмотрели 9,465 раз и оно понравилось 98 людям.