Reviewing React hooks
We have seen quite a few hooks provided by React. Let's take a moment to review what we have learned so far:
- Update a state with the
useState
hook. - Handle a side effect with the
useEffect
hook. - Reuse the last value with the
useMemo
hook. - Update an area with the
useContext
hook. - Hide stuff from display with the
useRef
hook.
The useState
hook is the most popular one, which is used to define a state and make it dispatchable to trigger a UI update. React wants us to use this as the main mechanism to be in sync with the screen. A mental picture of using it is that, as long as the state changes, the UI should produce an outcome accordingly. Otherwise, the UI should stay intact. Essentially, what that is saying is to make something happen on the screen, design a state and wire it with elements. This is the React way. If you take this as a baseline, it can help you understand anything else.
The useEffect
hook allows us to listen...