Summary
In this chapter, we first learned what a React ref is. We then went over how to access a DOM element by using a ref and went through the design of the useRef
hook, and saw how to persist a value without triggering a UI update. We also gave useRef
a test drive by walking through an input focus example. In the end, we went through how special it is by showing more examples of its use, including clicking outside of a menu, avoiding memory leaks, setting up a mule, and locating the current value.
In the next chapter, we will put all the hooks we have learned so far together and see how to finally create your custom hook, tailored to solve your own problems.