- 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.
- The Complete Rust Programming Reference Guide
- C語言程序設(shè)計(第3版)
- 深入理解Django:框架內(nèi)幕與實現(xiàn)原理
- Mastering Entity Framework
- DevOps入門與實踐
- INSTANT Sencha Touch
- 區(qū)塊鏈:以太坊DApp開發(fā)實戰(zhàn)
- Java持續(xù)交付
- 深度強化學(xué)習(xí)算法與實踐:基于PyTorch的實現(xiàn)
- jQuery開發(fā)基礎(chǔ)教程
- 編程數(shù)學(xué)
- Learning Vaadin 7(Second Edition)
- Tableau 10 Bootcamp
- ActionScript 3.0從入門到精通(視頻實戰(zhàn)版)
- Mastering Elixir