# Warning: A component is changing a controlled input to be uncontrolled (or vice versa). Input elements should not switch from controlled to uncontrolled (or vice versa). Decide between using a controlled or uncontrolled input element for the lifetime of the component.

- **ID:** `react/controlled-input-with-null-value`
- **Domain:** react
- **Category:** runtime_error
- **Verification:** ai_generated
- **Fix Rate:** 88%

## Root Cause

An input's value prop changed from a defined value to undefined or null (or vice versa) across renders, causing React to interpret the input as switching between controlled and uncontrolled modes.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| React 16.8+ | active | — | — |
| React 17.0.2 | active | — | — |
| React 18.2.0 | active | — | — |

## Workarounds

1. **Ensure the value prop is always a defined string or number. For example: <input value={state ?? ''} onChange={...} />** (85% success)
   ```
   Ensure the value prop is always a defined string or number. For example: <input value={state ?? ''} onChange={...} />
   ```
2. **If the value is intentionally null, use uncontrolled input with defaultValue and a key to reset: <input key={resetKey} defaultValue={initialValue} />** (70% success)
   ```
   If the value is intentionally null, use uncontrolled input with defaultValue and a key to reset: <input key={resetKey} defaultValue={initialValue} />
   ```

## Dead Ends

- **Setting value to empty string '' instead of null/undefined** — If the underlying state is null, converting to '' may mask the real issue and cause empty input when user expects null state. (30% fail)
- **Using defaultValue instead of value** — Switching to uncontrolled mode may break form logic if you need to programmatically update the input value later. (50% fail)
- **Adding a key prop to force remount** — Remounting the component on every state change defeats the purpose of controlled inputs and may cause performance issues or loss of focus. (60% fail)
