How to Restore Text Into React Inputs

Published: October 1, 2026. Updated: October 2026 by Andrew Apell, who builds Form ReDraft

Quick Answer

Short answer: Set the value through the native property setter on the input prototype, then dispatch a bubbling input event so React sees it and updates its own state. Assigning straight to the element's value updates the DOM but leaves React's model untouched. That is why restored text in React inputs disappears at the next render.

Key Takeaways

  • React keeps its own copy of the value, so the DOM and the model can disagree. A render settles that disagreement in favour of the model.
  • The native setter gets past the framework's own value tracking. The input event tells the framework that something changed.
  • A restore is only finished when the value survives a re-render. The test is part of the implementation, not an optional check.

If you have written an extension, an autofill script or a test harness that puts text into a React form, you have probably met this. The value appears in the box, then vanishes a moment later as soon as anything causes a re-render.

It is not a React bug. React is doing exactly what it was designed to do. Understand the design and a mysterious failure turns into a short recipe.

What a Controlled Input Actually Is

In a controlled input, React owns the value. The component receives a value prop, renders it into the element and keeps the same value in its own state. It updates that state when a change event arrives.

The element now has two descriptions of its contents: what the DOM holds and what React believes it holds. They agree while a person types, because typing produces the events React listens for. They diverge the moment something changes the DOM without producing those events.

Why the Property Setter Is the Problem

React does not read the DOM on every render, so it cannot notice a value written behind its back. On the next render it writes its own state into the element. The injected text is replaced by whatever the model still holds, which is whatever was there before.

There is a subtler trap too. React installs its own setter on the element instance to track changes. Assigning to element.value can update the visible box while bypassing the tracking that would tell React anything happened. The screen briefly agrees. The state never does.

The Native Setter

The way past that is to reach the setter defined on the prototype, not the one installed on the instance. For an input, take the descriptor from the platform's own prototype and call it with the element as the receiver. That changes the DOM value without touching React's bookkeeping.

This works because the prototype setter is what the platform would have used before any framework wrapped it. It sets the value the way a native assignment would, so the DOM reaches the correct state. The framework's own tracking is left alone, to be notified by the event that follows.

The Sequence That Works

  1. Focus the element. Many components only accept input while the field is active, and some ignore changes made while it is not.
  2. Call the native value setter from the prototype with the element as the receiver, so the DOM value changes without React noticing yet.
  3. Dispatch an input event that bubbles, so the framework's handler runs and copies the new value into its state.
  4. Dispatch a change event as well, for components that listen only for that and for any handler the site attached to the field.
  5. Re-render deliberately or wait for the next natural render, then confirm the text is still in the box.

How to Test That You Got It Right

The visible value is not the measurement. Trigger a state change after restoring, either by typing a character or by causing the component to update, then watch whether the restored text remains. If it disappears, the event never reached the handler and the framework still holds the old value.

A second test catches the opposite failure. Restore into an empty field, then submit the form. If the submitted payload contains the old value, the box and the model were never reconciled, whatever the screen showed.

Contenteditable Surfaces

Rich text editors are not inputs, so the prototype trick has nothing to attach to. The surface is a contenteditable element, and its value lives in the DOM tree as nodes, not in a value property.

The sequence is different, the principle is the same. Change the content the way the editor expects, then dispatch the event it listens for, usually an input event with the appropriate input type. Frameworks such as Slate, ProseMirror and Lexical each maintain their own model, and a restore that does not go through their API is a DOM change they will overwrite. Editors are the case where reading the library's documentation is not optional.

FAQ

Why does my restored text disappear from a React input?

Because the value was written to the element without React hearing about it. React still holds the old value in its own state and overwrites the element on the next render.

What is the native value setter?

It is the original set function defined on HTMLInputElement.prototype or HTMLTextAreaElement.prototype. Calling it directly writes the value without triggering framework bookkeeping.

Do I need to dispatch a change event as well?

Dispatch input first, because that is what modern frameworks listen for. Dispatch change afterwards for older code and for plain page scripts.

Does the same trick work for contenteditable editors?

Yes, but without the setter. Write the text into the element and dispatch a bubbling input event, which is what editors such as ProseMirror and Quill listen for.

Restore Into the Framework, Not the Screen

Form ReDraft writes through the page interface so that React, Vue and Angular keep your restored text instead of overwriting it on the next render.

Read the documentation
Project Slidecut