{"success":true,"name":"react-inputs-a-value-without-onchange-freezes-the-field-and-","description":"Working in React and a form field won't accept typing, or logs a controlled/uncontrolled warning","category":"ai-brimind","path":"ai-brimind/react-inputs-a-value-without-onchange-freezes-the-field-and-/SKILL.md","file":"SKILL.md","content":"---\nname: react-inputs-a-value-without-onchange-freezes-the-field-and-\ndescription: \"Working in React and a form field won't accept typing, or logs a controlled/uncontrolled warning\"\n---\n\n# React Inputs: A value Without onChange Freezes the Field, and Controlled Must Never Flip to Uncontrolled\n\n## When to use\nProject is React, and an input ignores keystrokes, a checkbox won't toggle, or the console warns about a component changing between controlled and uncontrolled.\n\n## Example request\ninput given value={text} with no onChange → React repaints the same value over every keystroke; frozen field. value starts as undefined, later becomes data → React saw uncontrolled, then controlled; the flip warning. mixing defaultValue with a later value → two ownership models on one field; confused input. — each left the question 'who owns this value?' unanswered.\n\n## Instructions\nAct as a React mechanic who first asks of every form field: who owns its value — my state, or the DOM? React offers exactly two contracts and demands you pick one per field. Controlled: your state owns it — pass value AND onChange together, updating state on every change; the frozen-input bug is precisely a value without its onChange, where React dutifully repaints your unchanging state over each keystroke. Uncontrolled: the DOM owns it — pass defaultValue for the initial content, read the value at submit time via a ref, and never pass value at all. The flip warning means a field switched contracts mid-life, and its usual cause is innocent: state initialized as undefined (from data not yet loaded), because React reads value={undefined} as 'uncontrolled' — initialize with an empty string or the appropriate empty value, and when populating a form from fetched data, coalesce missing fields to empty rather than passing undefined through. Checkboxes follow the same law with checked and defaultChecked. Choose per situation — controlled when you need live validation or dependent fields, uncontrolled for simple submit-time reads — and never mix the two prop families on one element. Only proceed once every field in the change declares its owner explicitly, because a field with an ambiguous owner obeys neither.\n\n## Metadata\n- role: developer\n- level: tactical\n- places: vibeCoding\n- origin: ai.brimind.pro skill #789\n","linked_files":[],"origin":"ai.brimind.pro","owner_id":null,"source":"router"}