Loading tutorials
useRef is one of the smallest hooks in React, and it is often misread. This chapter covers what it returns and how that object behaves across renders. Later chapters build on that behavior for DOM access, timers, and effects.5 min readuseRef keeps a value between renders without causing a render. It assumes you know JavaScript closures, function components and JSX, useState and re-rendering, and basic useEffect. The next chapter covers how to choose between a ref and state. This one covers the mech6 min readuseState and re-rendering, and basic useEffect. Earlier chapters covered what useRef returns and why its value survives renders. Here the question is which of the two tools fits a given piece of data.5 min readuseState, and basic useEffect. You should also know what a DOM element is, and what focus and scrolling mean in a browser.5 min readuseRef: focusing an element, scrolling it into view, and measuring its size and position. It assumes you know useState, basic useEffect, and how to attach a ref to a DOM element with the ref attribute.5 min readuseRef: holding values your component needs to remember but never shows on screen. It assumes you know JavaScript closures, function components, useState, and basic useEffect. Earlier chapters showed that a ref survives renders without causin6 min readuseRef API from earlier chapters. You should also know that a ref is an object shaped like { current: value } that React keeps between renders.5 min readuseEffect work together. It assumes you know JavaScript closures, function components and JSX, useState, the basic shape of useEffect(setup, deps), and what ref.current is. The rules for reading and writing ref.current during rendering are in the previous c6 min readuseState and re-rendering, and basic useEffect. It also assumes you know what a ref is, how useRef returns a { current } object, and how to attach one to a DOM element. Here you will learn the mistakes that come 5 min readuseRef returns a { current } object and how to attach one to a DOM element with the ref attribute. You should also be comfortable with useState, useEffect, and closures.6 min readuseRef, you know that ref.current is null until the componen5 min readuseRef basics, the rule against reading or writing ref.current during rendering, and how useState and useEffect work. It covers the one case where React allows you to touch ref.current while rendering. That case is creating an expensive value once.5 min readuseRef for a single DOM node, useState, and how map renders lists with key. It covers how to hold a ref to each item of a list when you don't know how many items there will be.5 min readuseRef attaches to a DOM element, how a parent can pass a ref to a child component, and how closures capture values in function components. It builds on the previous chapter, which covered passing refs to child components.5 min readuseRef: keeping the newest version of a callback or value available inside a long-lived effect, without restarting that effect each time the value changes.6 min read