- Hands-On Design Patterns with React Native
- Mateusz Grzesiukiewicz
- 377字
- 2021-08-13 15:12:55
What are the advantages of stateless components?
It may seem tempting to only use stateful class components and develop a whole application like that. Why would we even bother with stateless functional components? The answer is performance. Stateless functional components can be rendered faster. One of the reasons why this is the case is because stateless functional components do not require some of the life cycle hooks.
These are useful to trigger fetching data from the API or to update the view.
Please note that if you are using React v16 or later, it is not true that functional components are wrapped into class components internally within the React library:
- Dominic Gannaway, engineer on the React core team at Facebook (https://github.com/reactjs/reactjs.org/issues/639#issuecomment-367858928)
Functional components are faster, but in most cases are outperformed by class components extending React.PureComponent:
- Dan Abramov, co-author of Redux and Create React App, engineer on the React core team at Facebook (https://twitter.com/trueadm/status/916706152976707584)
Functional components are not only more concise, but they usually are also pure functions. We will explore this concept further in Chapter 9, Elements of Functional Programming Patterns. Pure functions provide a lot of benefits, such as a predictable UI and easy tracking of user behavior. The application can be implemented in a certain way to record user actions. Such data helps with debugging and reproducing errors in tests. We will dig into this topic later on in this book.
- Cocos2d Cross-Platform Game Development Cookbook(Second Edition)
- Boost.Asio C++ Network Programming(Second Edition)
- Learning ROS for Robotics Programming(Second Edition)
- Mastering SVG
- OpenCV 3和Qt5計算機視覺應用開發
- 64位匯編語言的編程藝術
- 用Flutter極速構建原生應用
- Serverless架構
- 青少年學Python(第1冊)
- Learning Unreal Engine Android Game Development
- Spring Boot+MVC實戰指南
- 3ds Max印象 電視欄目包裝動畫與特效制作
- Practical Microservices
- Julia High Performance(Second Edition)
- Spring Data JPA從入門到精通