Search⌘ K
AI Features

Using Refs for Uncontrolled Inputs

Explore how to handle uncontrolled form inputs in React by using useRef. This lesson teaches reading input values directly from the DOM, focusing elements, and resetting forms without React state, ideal for simple or quick forms and third-party integrations.

Controlled components keep the UI and state perfectly in sync, but they can feel verbose for quick, low-logic forms or when integrating with third-party widgets that manage their own internal state. In such cases, letting the DOM hold the value and reading it on demand via useRef can be simpler and sometimes more performant. Remember, useRef allows us to create a reference to a DOM element or a mutable value that persists across renders without reinitializing. The trade-off is that we don’t get real-time React state updates as the user types; instead, we explicitly read values when needed (for example, on form submission).

Understanding the uncontrolled inputs

An uncontrolled input is a standard <input> (or <textarea>, <select>) whose current value lives ...