Best Way to Create Functional Component in Modern React JS Example

preview_player
Показать описание
In this video, we discussed how to create a functional component in React and the advantages of functional components over class components. What are the reasons developers/programmers prefer to use functional components over class components in React?
Below are some reasons to use the functional component over react class component:
1. Functional components are much easier to read and test because they are plain JavaScript functions without state or lifecycle hooks you end up with less code.
2. It will get easier to separate container and presentational components because you need to think more about your component’s state if you don’t have access to setState() in your component.
3. The React team mentioned that there may be a performance boost for the functional components in future React versions.
4. There is one difference in the syntax. A functional component is just a plain JavaScript function that 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 that returns a React element. This requires more code but will also give some benefits.
Рекомендации по теме
welcome to shbcf.ru