Chapter 6: Use Memo to Boost Performance
In the previous chapter, we learned how the useEffect
hook is designed and how to use it to manage a side effect in React. In this chapter, we will change to an optimization topic for reusing the last assignment. We will first introduce how we can run into performance degradation in a typical web application. Then, we will walk through the design and source code behind useMemo
and describe various ways of reusing a value conditionally. We'll then apply the optimization technique to two common cases: clicking to search and debouncing the search. At the end, the chapter also includes two bonus topics in the Appendix section, Not a Classical Memorization and Skipping a Child Update.
We will cover the following main topics in this chapter:
- Performance degradation
- Understanding the
useMemo
design - Reusing a last assignment
- Test-Driving
useMemo
useMemo
examples- Questions and answers
- Appendix