-
Book Overview & Buying
-
Table Of Contents
-
Feedback & Rating
Learn React with TypeScript - Third Edition
By :
In this chapter, we learned that all React Hooks must be called at the top level of a function component and can’t be called conditionally.
The useEffect Hook can be used to execute component side effects when it is rendered. We learned how to use useEffect to fetch data, which is a common use case.
useReducer is an alternative to useState for using state, and we experienced using both approaches in our PersonScore example component. useState is excellent for primitive state values. useReducer is great for complex object state values, particularly when state changes depend on previous state values.
The ref Hook creates a mutable value and doesn’t cause a re-render when changed. We used useRef to set focus to an HTML element after it was rendered, which is a common use case.
The useMemo and useCallback Hooks can be used to memoize values and functions, respectively, and can be used for performance optimization. The examples we used for these Hooks were...